Если ваш класс Item
имеет строковый конструктор, он будет вызываться со значением "simpleType"
.
class Item {
private String name;
private String functionName;
public Item() {
}
public Item(String name) {
this.name = name;
}
// getters and setters here
}
Полная демонстрация
public class Request {
public static void main(String[] args) throws IOException {
String json = "{\"subItems\":[" +
"{\"name\":\"complexType\",\"functionName\":\"SomeFunction\"}," +
"\"simpleType\"" +
"]}";
Request request = new ObjectMapper().readValue(json, Request.class);
System.out.println(request);
}
private List<Item> subItems;
public Request() {
}
public Request(Item... subItems) {
this.subItems = Arrays.asList(subItems);
}
public List<Item> getSubItems() {
return this.subItems;
}
public void setSubItems(List<Item> subItems) {
this.subItems = subItems;
}
@Override
public String toString() {
return "Request [subItems=" + this.subItems + "]";
}
}
class Item {
private String name;
private String functionName;
public Item() {
}
public Item(String name) {
this.name = name;
}
public Item(String name, String functionName) {
this.name = name;
this.functionName = functionName;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getFunctionName() {
return this.functionName;
}
public void setFunctionName(String functionName) {
this.functionName = functionName;
}
@Override
public String toString() {
return "Item [name=" + this.name + ", functionName=" + this.functionName + "]";
}
}
выход
Request [subItems=[Item [name=complexType, functionName=SomeFunction], Item [name=simpleType, functionName=null]]]