0

Similar to this stackoverflow thread Jackson with JSON: Unrecognized field, not marked as ignorable

I am getting com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field error.

I don't want to have to save this value in a field on the class. I want it to be computed when it is being serialized. And possibly ignored when it is being deserialized (because then I can just recompute it)

I think this may have to do with the fact that these methods are never called. Because other computed methods which being called are being serialized just fine.

janst
  • 102
  • 10

1 Answers1

1

If the method returns a value computed from other properties, make sure it is ignored by Jackson by adding @ com.fasterxml.jackson.annotation.JsonIgnore to the method.

Alternatively - if you want to serialize the value and ignore it/not fail on deserialization then there are two options I know of:

  • add @JsonIgnoreProperties(ignoreUnknown=true) to the class
  • or call mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) on the ObjectMapper you are using for deserialization.
Askin Geeks
  • 303
  • 2
  • 5
  • 14
  • So in my case I have an Object which contains a Collection of other objects. In order to calculate the computed field, it must iterate and aggregate all the individual sums of the objects in this collection. I'm starting to think that this is not possible to do with json during something like a 'pre-serialize' method. I'll just need to supply data members and update them in batches. – janst Mar 30 '21 at 01:41