Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new module for deserialization in the @Filter annotation #327

Closed
sondavide opened this issue Sep 27, 2023 · 4 comments
Closed

Add new module for deserialization in the @Filter annotation #327

sondavide opened this issue Sep 27, 2023 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@sondavide
Copy link

Hi, I'm using the last release 3.1.5:

com.turkraft.springfilter mongo 3.1.5

There is a way to register a new or custom module in the ObjectMapper deserializers?

If I have a class with a field of type Instant, this error comes out:

"Query: { "$expr" : { "$gte" : ["$instant", "[ERROR: (com.fasterxml.jackson.databind.exc.InvalidDefinitionException) Java 8 date/time type java.time.Instant not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling]"]}}, Fields: {}, Sort: {}"

There's a way to add jackson-datatypee-jsr310?

@torshid
Copy link
Member

torshid commented Sep 27, 2023

Hi @sondavide,

Spring Filter simply autowires the present ObjectMapper bean, without making any configuration to it. You may customize that behavior as it may be done in any Spring project, see this for example.

@torshid torshid closed this as completed Sep 27, 2023
@torshid torshid added the help wanted Extra attention is needed label Sep 27, 2023
@sondavide
Copy link
Author

sondavide commented Sep 27, 2023

Hi @torshid , thanks for the help.
I'm trying to understand the problem, it's not a deserialization problem, because the JsonNodeHelperImpl has the correct ObjectMapper and the rightResult in the transform function is of type Instant.
If I use the classic mongo repository query:

    @Query("{$expr: {$eq: ['$DATA_INSTALLAZIONE', ?0 ]}}")
    List<Civic> getByDate(Instant data);

it works and finds the correct datas, if I use the @filter annotation, something does not work

@sondavide
Copy link
Author

finally I used a custom converter:


@Service
public class CustomInstantConverter implements Converter<String, CustomInstant> {

  @Override
  public CustomInstant convert(String source) {
    return new CustomInstant(source);
  }

  @Data
  @NoArgsConstructor
  public static class CustomInstant implements Serializable {

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class DateFromString implements Serializable{
        public String dateString;
    }


    @JsonProperty("$dateFromString")
    public DateFromString dateFromString;

    public CustomInstant(String source) {
        this.dateFromString= new DateFromString(source);
    }


  }


}

$dateFromString saved me

@torshid
Copy link
Member

torshid commented Sep 27, 2023

Thanks for sharing the solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants