open API
jackson same name but different types
張's blog
2021. 5. 14. 16:24
- 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
- tyoe을 Object로 하면 Map이나 List<Map>로 변환 함
dto사용시 문제소지 있음
https://stackoverflow.com/questions/15626384/java-and-json-jackson-property-different-types-at-run-time