jacksonオブジェクトマッパーを使用してバイト配列をJava型に逆シリアル化しようとしています。Jackson Object Mapperすべてのフィールドがnullに初期化されたオブジェクトを返すバイト単位の読み取り値
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class A {
String s;
String b;
}
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class B {
String c;
String b;
}
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class C {
List<CustomType> x;
}
とジャクソン法を使用して、
objectMapper.readValue(byte[] data, Class<T> type).
私はバイト配列が含まれているオブジェクトをどのようなわからないように、私はそれを指定した型のオブジェクトを作成することができない場合に失敗することにしたいです。ただし、objectMapperはすべてのフィールドがNULLに初期化されたオブジェクトを返します。どのように私はこの動作を避けるのですか?
Ex:
byte[] b; //contains Class B data
byte[] a; //contains Class A data
byte[] c// contains Class C data
A a = objectMapper.readValue(c, A.class) is returning
{s=null, b = null}
と私はObjectMapperを設定しているOWこれは、
@Bean
public ObjectMapper objectMapper(HandlerInstantiator handlerInstantiator) {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
builder.handlerInstantiator(handlerInstantiator);
builder.failOnEmptyBeans(false);
builder.failOnUnknownProperties(false);
builder.simpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
builder.timeZone("UTC");
builder.serializationInclusion(JsonInclude.Include.NON_NULL);
return builder.build();
}
[mcve]を入力してください。 –
@SotiriosDelimanolisは応答に感謝します。私は再現するために必要なものすべてを含んでいます。簡単にするために、私はJavaオブジェクトのgetterとsetterを削除しました。 – Bharath
@Bharathいいえ、あなたはしませんでした。 – lexicore