我通过REST API获得了以下JSON对象,我想将其转换为POJO-s - object。我是在http://www.jsonschema2pojo.org/网站上做到的,收到了以下代码。我只是无法成功地将JSON映射到对象数据。
{"categories":[{"categories":{"id":1,"name":"Delivery"}},{"categories":{"id":2,"name":"Dine-out"}},{"categories":{"id":3,"name":"Nightlife"}},{"categories":{"id":4,"name":"Catching-up"}},{"categories":{"id":5,"name":"Takeaway"}},{"categories":{"id":6,"name":"Cafes"}},{"categories":{"id":7,"name":"Daily Menus"}},{"categories":{"id":8,"name":"Breakfast"}},{"categories":{"id":9,"name":"Lunch"}},{"categories":{"id":10,"name":"Dinner"}},{"categories":{"id":11,"name":"Pubs & Bars"}},{"categories":{"id":12,"name":"Premium Delivery"}},{"categories":{"id":13,"name":"Pocket Friendly Delivery"}},{"categories":{"id":14,"name":"Clubs & Lounges"}}]}
以下是REST API网站的模型:
// MODEL:
Inline Model [
Categories
]
Categories {
category_id (integer): ID of the category type ,
category_name (string): Name of the category type
}
// MODEl Schema
[
{
"category_id": "3",
"category_name": "Nightlife"
}
]
生成的POJO:
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonInclude(JsonInclude.Include.NON_NULL)
@Generated("org.jsonschema2pojo")
@JsonPropertyOrder({
"id",
"name"
})
public class Categories {
@JsonProperty("id")
private Integer id;
@JsonProperty("name")
private String name;
/**
*
* @return
* The id
*/
@JsonProperty("id")
public Integer getId() {
return id;
}
/**
*
* @param id
* The id
*/
@JsonProperty("id")
public void setId(Integer id) {
this.id = id;
}
/**
*
* @return
* The name
*/
@JsonProperty("name")
public String getName() {
return name;
}
/**
*
* @param name
* The name
*/
@JsonProperty("name")
public void setName(String name) {
this.name = name;``
}
}
@JsonInclude(JsonInclude.Include.NON_NULL)
@Generated("org.jsonschema2pojo")
@JsonPropertyOrder({
"categories"
})
public class Category {
@JsonProperty("categories")
private Categories categories;
/**
*
* @return
* The categories
*/
@JsonProperty("categories")
public Categories getCategories() {
return categories;
}
/**
*
* @param categories
* The categories
*/
@JsonProperty("categories")
public void setCategories(Categories categories) {
this.categories = categories;
}
}
@JsonInclude(JsonInclude.Include.NON_NULL)
@Generated("org.jsonschema2pojo")
@JsonPropertyOrder({
"categories"
})
public class Example {
@JsonProperty("categories")
private List<Category> categories = new ArrayList<Category>();
/**
*
* @return
* The categories
*/
@JsonProperty("categories")
public List<Category> getCategories() {
return categories;
}
/**
*
* @param categories
* The categories
*/
@JsonProperty("categories")
public void setCategories(List<Category> categories) {
this.categories = categories;
}
}
请您帮我正确定位映射器吗?