You can use Jackson's annotation to provide a specific deserializer.
@JsonDeserialize(using = ADeserializer.class)
public class A {
private String field;
private B b;
}
The separator for your type should look like this
public class ADeserializer extends JsonDeserializer<A> {
@Override
public A deserialize(JsonParser p, DeserializationContext ctx) throws IOException {
ObjectCodec codec = p.getCodec();
JsonNode node = codec.readTree(p);
String field = node.get("field").asText();
int n = node.get("n").asInt();
A a = new A();
B b = new B();
b.setN(n);
a.setField(field);
a.setB(b);
return a;
}
}
Serializer. .