Using spring-data-elasticsearch in version 2.2.0 (+ project lombok)
I want to deserialize a JSON response to a Java class. Every field/object except for an JSON array works fine. The Java list "bs" which should contain the B objects from the JSON array stays null.
The JSON response with the array looks like this:
...
"_index": "someIndex",
"_type": "A",
"_id": "someId",
"_score": 0,
"_source": {
...
"bs": [
{
"number": "0000000001234",
"type": "03"
},
{
"number": "4008123694567",
"type": "13"
}
],
...
}
...
The JSON array "bs" should be deserialized to the Java list bs. The Java class A which contains a list of Bs looks like this:
@Data
@Builder
@AllArgsConstructor(suppressConstructorProperties = true)
@NoArgsConstructor
@Document(indexName = "#{AIndexType.getIndexName()}", type = "#{AIndexType.getTypeName()}")
public class A implements Serializable {
...
@Field(type = FieldType.Nested)
private List<B> bs;
}
Class B looks like this:
@Data
@AllArgsConstructor(suppressConstructorProperties = true)
@NoArgsConstructor
public class B implements Serializable {
private String number;
private String type;
}
Using the @Field annotation with FieldType.NESTED doesn't seem to work/make any difference to not using it. Do I have to write a custom deserializer (for the list bs) or is there any other way to get this working?
See comment above.
The problem is solved, there was a link (/wrong use of properties) to another elasticsearch instance which actually had no instances of B.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.