6

I am trying to make thrift deserialization for jackason backward compatible

ObjectMapper mapper = getObjectMapper(false /* pretty */);
mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true); // This works

// This doesn't work
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);


MapLikeType t = mapper.getTypeFactory().constructMapLikeType(LinkedHashMap.class, keyClass, valueClass);
return mapper.readValue(content, t);

valueClass is of the following type

public class MyThrift implements org.apache.thrift.TBase<MyThrift, MyThrift._Fields>, java.io.Serializable, Cloneable, Comparable<MyThrift> {

I keep getting

com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not construct instance of com.MyThrift$_Fields from String value 'MY_ID': value not one of declared Enum instance names

if I use FAIL_ON_UNKNOWN_PROPERTIES

But I don't get the same error if I use READ_UNKNOWN_ENUM_VALUES_AS_NULL , can someone point me a direction on why using FAIL_ON_UNKNOWN_PROPERTIES not work?

Does jackason bind not support FAIL_ON_UNKNOWN_PROPERTIES for thrift ?

user10714010
  • 865
  • 2
  • 13
  • 20

1 Answers1

2

FAIL_ON_UNKNOWN_PROPERTIES is for the property names of your object. READ_UNKNOWN_ENUM_VALUES_AS_NULL is for the property value.

So if you had a JSON string that looked like this:

{
"property1": "ENUM_ONE",
"property2": "ENUM_TWO"
}

You would use FAIL_ON_UNKNOWN_PROPERTIES, for example, if your value object didn't have getProperty2/setProperty2, whereas you would useREAD_UNKNOWN_ENUM_VALUES_AS_NULL if ENUM_TWO did not exist in your enum.

Frank Riccobono
  • 1,043
  • 6
  • 13