jackson same name but different types
- JsonNode를 이용한 방법
private String strData;
private List<String> listData;
@JsonProperty("date")
public Object getData() {
조건문..
return 알맞은값
}
@JsonProperty("date")
public void setData(JsonNode){
if(node.getNodeType() == JsonNodeType.STRING){
strData = node.textValue();
} else if(node.getNodeType() == JsonNodeType.ARRAY){
ObjectMapper mapper = new ObjectMapper();
listData = mapper.convertValue(node, List.class);
}
}
https://stackoverflow.com/questions/21790727/providing-jackson-mapper-multiple-ways-to-deserialize-the-same-object/27068928#27068928
Providing Jackson Mapper multiple ways to deserialize the same object
I'm trying to deserialize two types of json: { name: "bob", worksAt: { name: "Bobs department store", location: "downtown" }, age: 46 } and { name: "Tom",
stackoverflow.com
Deserializing attributes of same name but different types in Jackson?
I have a REST API which returns a JSON response as: { "channel" : "JHBHS" } and sometimes it returns: { "channel": { "id": 12321, "name": "Some ch...
stackoverflow.com
- tyoe을 Object로 하면 Map이나 List<Map>로 변환 함
dto사용시 문제소지 있음
https://stackoverflow.com/questions/15626384/java-and-json-jackson-property-different-types-at-run-time
java and json jackson property - different types at run-time
I am calling an external web-service to get an object as json. This object has a property "value" which is sometimes a String and sometimes an array of Strings. public class MyClass { // ......
stackoverflow.com