So I am building a REST api using SpringDataRest both Get and Post are working but I don´t know whats wrong with the PUT.
This is the entity im using:
#Entity
#Table(name = "companies")
public class Company {
#Id
#Column(name="CompanyId", nullable=false, unique=true)
private String companyId;
#Column(name="Name", nullable=false)
private String name;
#Column(name="ContactName", nullable=false)
private String contactName;
#Column(name="ContactSurName")
private String contactSurname;
#Column(name="ContactEmail", nullable=false)
private String contactEmail;
#Column(name="ContactPhone")
private String contactPhone;
#Column(name="Enabled", nullable=false)
private String enabled;
#Column(name="Logo")
private String logo;
#Column(name = "CreationDate", columnDefinition="DATETIME")
#Temporal(TemporalType.TIMESTAMP)
private Date creationDate;
#Column(name = "LastUpdateDate", columnDefinition="DATETIME")
#Temporal(TemporalType.TIMESTAMP)
private Date lastUpdateDate;
//Region Constructors
private Company(){}
public Company(String companyId, String name, String contactName, String contactSurname, String contactEmail, String contactPhone,
String enabled){
this.companyId = companyId;
this.name = name;
this.contactName = contactName;
this.contactSurname = contactSurname;
this.contactEmail = contactEmail;
this.contactPhone = contactPhone;
this.enabled = enabled;
this.creationDate = new Date();
this.lastUpdateDate = new Date();
}
//EndRegion
//Region Getters & Setters
public String getCompanyId() {
return companyId;
}
public void setCompanyId(String companyId) {
this.companyId = companyId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getContactName() {
return contactName;
}
public void setContactName(String contactName) {
this.contactName = contactName;
}
public String getContactSurname() {
return contactSurname;
}
public void setContactSurname(String contactSurname) {
this.contactSurname = contactSurname;
}
public String getContactEmail() {
return contactEmail;
}
public void setContactEmail(String contactEmail) {
this.contactEmail = contactEmail;
}
public String getContactPhone() {
return contactPhone;
}
public void setContactPhone(String contactPhone) {
this.contactPhone = contactPhone;
}
public String getEnabled() {
return enabled;
}
public void setEnabled(String enabled) {
this.enabled = enabled;
}
public String getLogo() {
return logo;
}
public void setLogo(String logo) {
this.logo = logo;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getLastUpdateDate() {
return lastUpdateDate;
}
public void setLastUpdateDate(Date lastUpdateDate) {
this.lastUpdateDate = lastUpdateDate;
}
//EndRegion
}
When I execute this request:
REQUEST
I get this response:
{
"cause": {
"cause": null,
"message": "No content to map due to end-of-input\n at [Source: org.apache.catalina.connector.CoyoteInputStream#1130374; line: 1, column: 0]"
},
"message": "Could not read an object of type class com.wipma.application.domain.Company from the request!; nested exception is com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input\n at [Source: org.apache.catalina.connector.CoyoteInputStream#1130374; line: 1, column: 0]"
}
I can´t figure out whats wrong, I suspect its something related with some field mapping but cant sort it out.
Thanks in advance
Related
I am having an unusual error, when doing a get in postman, my method returns some values called target and targetClass, I don't know why, since I am implementing an interface just to bring some specific values, if you could help would be very appreciated
This is the model
#Entity
#Table(name = "tudb_users")
public class Tudb_users {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "user_id")
private int userId;
#Column(name = "client_id")
private Integer clientId;
#Column(name = "name")
private String name;
#Column(name = "last_name")
private String lastName;
#Column(name = "rol_id")
private Integer rolId;
#Column(name = "clinic_id")
private Integer clinicId;
#Column(name = "password")
private String password;
#Column(name = "rfc")
private String rfc;
#Column(name = "gender")
private Integer gender;
#Column(name = "date_born")
private String dateBorn;
#Column(name = "email")
private String email;
#Column(name = "phone")
private String phone;
#Column(name = "identification_card")
private String identificationCard;
#Column(name = "photo")
private String photo;
#Column(name = "folder")
private String folder;
#Column(name = "session")
private Integer session;
#Column(name = "promotion_code")
private String promotionCode;
#Column(name = "last_session")
#Temporal(TemporalType.TIMESTAMP)
#JsonFormat(pattern = "yy-MM-dd' 'HH:mm")
private Date lastSession;
#Column(name = "token")
private String token;
#Column(name = "token_email")
private String tokenEmail;
#Column(name = "status")
private Integer status;
#Column(name = "user_register")
private Integer userRegister;
#Column(name = "date_register")
#Temporal(TemporalType.TIMESTAMP)
#JsonFormat(pattern = "yy-MM-dd' 'HH:mm")
private Date dateRegister;
#Column(name = "user_update")
private Integer userUpdate;
#Column(name = "date_update")
#Temporal(TemporalType.TIMESTAMP)
#JsonFormat(pattern = "yy-MM-dd' 'HH:mm")
private Date dateUpdate;
#Column(name = "options")
private Integer options;
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public Integer getClientId() {
return clientId;
}
public void setClientId(Integer clientId) {
this.clientId = clientId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Integer getRolId() {
return rolId;
}
public void setRolId(Integer rolId) {
this.rolId = rolId;
}
public Integer getClinicId() {
return clinicId;
}
public void setClinicId(Integer clinicId) {
this.clinicId = clinicId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getRfc() {
return rfc;
}
public void setRfc(String rfc) {
this.rfc = rfc;
}
public Integer getGender() {
return gender;
}
public void setGender(Integer gender) {
this.gender = gender;
}
public String getDateBorn() {
return dateBorn;
}
public void setDateBorn(String dateBorn) {
this.dateBorn = dateBorn;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getIdentificationCard() {
return identificationCard;
}
public void setIdentificationCard(String identificationCard) {
this.identificationCard = identificationCard;
}
public String getPhoto() {
return photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
public String getFolder() {
return folder;
}
public void setFolder(String folder) {
this.folder = folder;
}
public Integer getSession() {
return session;
}
public void setSession(Integer session) {
this.session = session;
}
public Date getLastSession() {
return lastSession;
}
public void setLastSession(Date lastSession) {
this.lastSession = lastSession;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getUserRegister() {
return userRegister;
}
public void setUserRegister(Integer userRegister) {
this.userRegister = userRegister;
}
public Date getDateRegister() {
return dateRegister;
}
public void setDateRegister(Date dateRegister) {
this.dateRegister = dateRegister;
}
public Integer getUserUpdate() {
return userUpdate;
}
public void setUserUpdate(Integer userUpdate) {
this.userUpdate = userUpdate;
}
public Date getDateUpdate() {
return dateUpdate;
}
public void setDateUpdate(Date dateUpdate) {
this.dateUpdate = dateUpdate;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getTokenEmail() {
return tokenEmail;
}
public void setTokenEmail(String tokenEmail) {
this.tokenEmail = tokenEmail;
}
public Integer getOptions() {
return options;
}
public void setOptions(Integer options) {
this.options = options;
}
public String getPromotionCode() {
return promotionCode;
}
public void setPromotionCode(String promotionCode) {
this.promotionCode = promotionCode;
}
}
Now this is repository
#Repository
public interface TudbUsersRepository extends JpaRepository<Tudb_users, Long>{
#Query(value = "SELECT tudb_users.user_id, tudb_users.client_id, tu_clients.name as nameCliente, tudb_users.clinic_id, tudb_users.rol_id, tudb_roles.description as rolName, tudb_users.name, tudb_users.last_name,\r\n"
+ "tudb_users.email, tudb_users.photo, tudb_users.rfc, tudb_users.gender, tudb_users.date_born, tudb_users.folder, tudb_users.token\r\n"
+ "FROM dentabash_dev.tudb_users inner join tu_clients on tu_clients.client_id = tudb_users.client_id\r\n"
+ "inner join tudb_roles on tudb_roles.rol_id = tudb_users.rol_id where tudb_users.client_id = ?1", nativeQuery = true)
List<DentaUser> getUsersByClientId(Integer id);
}
This is the interface
public interface DentaUser {
Integer getUser_id();
Integer getClient_id();
Integer getClinic_id();
Integer getRol_id();
String getNameCliente();
String getRolName();
String getName();
String getLast_name();
String getEmail();
String getPhoto();
String getRfc();
Integer getGender();
#Temporal(TemporalType.TIMESTAMP)
#JsonFormat(pattern = "yy-MM-dd' 'HH:mm")
Date getDate_born();
String getFolder();
String getToken();
}
This is the service
#Service
public class TudbUsersServices {
#Autowired
private TudbUsersRepository repo;
public ResponseEntity<?> getUserByClientID(Integer id){
JSONObject response = new JSONObject();
try {
response.put("code", 200);
response.put("success", true);
response.put("data", repo.getUsersByClientId(id));
return new ResponseEntity<>(response.toString(), HttpStatus.OK);
}catch(Exception e) {
response.put("code", 400);
response.put("success", false);
response.put("message", "Bad request" + e.getMessage());
return new ResponseEntity<>(response.toString(), HttpStatus.OK);
}
}
}
And this is controller:
#RestController
#RequestMapping("/dbusers")
#Tag(name = "DentaBash Users", description = "DentaBash Users - Controller")
#CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.POST})
public class TudbUsersController {
#Autowired
private TudbUsersServices service;
#RequestMapping(value = "/usersByClient", method = RequestMethod.GET)
public ResponseEntity<?> getUserByClientID(#RequestParam Integer clientId){
return service.getUserByClientID(clientId);
}
}
Now I get this in postman:
{
"code": 200,
"data": [
{
"gender": 0,
"photo": "images/user.png",
"last_name": "Ortiz",
"client_id": 2,
"rfc": "TESTRFC",
"target": {
"gender": 0,
"last_name": "Ortiz",
"photo": "images/user.png",
"client_id": 2,
"rfc": "TESTRFC",
"token": "5mi7oit016l768aaj1mecgmgu6",
"folder": "images/test/folder",
"user_id": 4,
"date_born": "2022-02-01",
"name": "Juan",
"nameCliente": "Jose Luis Miranda Pavon",
"rol_id": 4,
"rolName": "Cirujano Dentista - Gerente",
"clinic_id": 1,
"email": "juan#gmail.com"
},
"token": "5mi7oit016l768aaj1mecgmgu6",
"folder": "images/test/folder",
"user_id": 4,
"targetClass": "class org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap",
"name": "Juan",
"nameCliente": "Jose Luis Miranda Pavon",
"rol_id": 4,
"rolName": "Cirujano Dentista - Gerente",
"clinic_id": 1,
"email": "juan#gmail.com"
}
],
"success": true
}
Customer entity
#Entity
#Table(name="Customer")
public class Customer {
#Id
#GeneratedValue
private Long cusId;
#Column(name="firstname")
private String firstName;
#Column(name="lastname")
private String lastName;
#Column(name="address")
private String add;
#Column(name="tel")
private int tel;
#Column(name="email")
private String email;
#Column(name="userName")
private String username;
#Column(name="password")
private String password;
#OneToMany(fetch = FetchType.EAGER, mappedBy = "customer")
#JsonManagedReference
private List<Complain> complain=new ArrayList<Complain>();
public Customer() {
super();
// TODO Auto-generated constructor stub
}
public Long getCusId() {
return cusId;
}
public void setCusId(Long cusId) {
this.cusId = cusId;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getAdd() {
return add;
}
public void setAdd(String add) {
this.add = add;
}
public int getTel() {
return tel;
}
public void setTel(int tel) {
this.tel = tel;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public List<Complain> getComplain() {
return complain;
}
public void setComplain(List<Complain> complain) {
this.complain = complain;
}
}
Complain Entity
#Entity
#Table(name="Complain")
public class Complain {
#Id
#GeneratedValue
private Long id;
#Column(name="repfirst")
private String repfirst;
#Column(name="replast")
private String replast;
#Column(name="warranty")
private String warranty;
#Column(name="dop")
private String purDate;
#Column(name="Nomachine")
private String Nomachine;
#Column(name="Complain")
private String Complain;
#ManyToOne(fetch = FetchType.EAGER)
#JoinColumn(name="cus_id", referencedColumnName = "cusId")
#JsonBackReference
private Customer customer;
public Complain() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getRepfirst() {
return repfirst;
}
public void setRepfirst(String repfirst) {
this.repfirst = repfirst;
}
public String getReplast() {
return replast;
}
public void setReplast(String replast) {
this.replast = replast;
}
public String getWarranty() {
return warranty;
}
public void setWarranty(String warranty) {
this.warranty = warranty;
}
public String getPurDate() {
return purDate;
}
public void setPurDate(String purDate) {
this.purDate = purDate;
}
public String getNomachine() {
return Nomachine;
}
public void setNomachine(String nomachine) {
Nomachine = nomachine;
}
public String getComplain() {
return Complain;
}
public void setComplain(String complain) {
Complain = complain;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
}
I want to pass data to the mysql database through the postman tool. How can I pass value for the foreign key column through the json query?
This is the method I have used in controller
#PostMapping(path="/",consumes="application/json",produces="application/json")
public void addComplain(#RequestBody Complain complain)
{
Integer id = complainService.getAllComplain().size()+1;
complain.setId(new Long(id));
complainService.createOrUpdateComplain(complain); }
After I send the request from the postman, all the data are saved except the foreign key. I think I missed something in mapping two tables.
This is my json query
{"complain":"No power",
"repfirst":"hi",
"replast":"all",
"warranty":"yes",
"purDate":"2020-02-29",
"nomachine":"6",
"tel":"46544654",
"Customer":[
{"cusId":"1"}
]
}
Database table image
Please help, Thanks in advance
{
"repfirst": "",
"replast": "",
"warranty": "",
"purDate" : "",
"Nomachine": "",
"Complain": "",
"cus_id": 1
}
That should work
"Customer":[
{"cusId":"1"}
]
This would work if you had Set<Customer> customers converted to an array in json, for example.
I want to pass following format while posting time using postmapping. so how can i write model and controller. I am new in spring boot so pls help me.
{
"request":
{
"name":"siva",
"mobile":"9788761376",
"parent":"1",
"description":"aaaa"
}
}
My model and controller
MODEL:
----------
#Entity
#Table(name = "project_category")
#EntityListeners(AuditingEntityListener.class)
#JsonIgnoreProperties(value = {"created_date", "updated_date"},
allowGetters = true)
public class ProjectCategoryModel {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private long id;
#NotBlank
private String name;
private String description;
private String parent;
#Column(nullable = false, updatable = false)
#Temporal(TemporalType.TIMESTAMP)
#CreatedDate
private Date created_date;
#Column(nullable = false)
#Temporal(TemporalType.TIMESTAMP)
#LastModifiedDate
private Date updated_date;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getParent() {
return parent;
}
public void setParent(String parent) {
this.parent = parent;
}
public Date getCreatedDate() {
return created_date;
}
public void setCreatedDate(Date created_date) {
this.created_date = created_date;
}
public Date getUpdatedDate() {
return updated_date;
}
public void setUpdatedDate(Date updated_date) {
this.updated_date = updated_date;
}
Controller:
#PostMapping("/project/category/create")
public ResponseEntity createProjectCategory(#Valid #RequestBody
ProjectCategoryModel projectCategory) {
String respId = "project.category.create";
Object dbResp = projectCategoryRepository.save(projectCategory);
ResponseDataBuilder rb = new ResponseDataBuilder();
HashMap<String, Object> respData = new HashMap<String, Object>();
respData.put("id",projectCategory.getId());
respData.put("responseCode", "OK");
respData.put("message","Project Category Created");
respData.put("apiId","project.category.create");
respData.put("ts", new Date(System.currentTimeMillis()));
HashMap<String, Object> responseObj = rb.getResponseData(respId,
respData);
ProjectCategoryResponse response = new ProjectCategoryResponse();
return response.sendResponse(responseObj);
}
=================================================================
===================================================================
In your model class i.e ProjectCategoryModel declare one custom type like Request
Create one class named as Request like this
public class Request{
private String name;
private String description;
private String parent;
private long mobile;
//getter and setter
}
Declare this type in ProjectCategoryModel :
MODEL:
----------
#Entity
#Table(name = "project_category")
#EntityListeners(AuditingEntityListener.class)
#JsonIgnoreProperties(value = {"created_date", "updated_date"},
allowGetters = true)
public class ProjectCategoryModel {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private Request request;
#Column(nullable = false, updatable = false)
#Temporal(TemporalType.TIMESTAMP)
#CreatedDate
private Date created_date;
#Column(nullable = false)
#Temporal(TemporalType.TIMESTAMP)
#LastModifiedDate
private Date updated_date;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Request getRequest(){
return request;
}
public void setRequest(Request request){
this.request = request;
}
public Date getCreatedDate() {
return created_date;
}
public void setCreatedDate(Date created_date) {
this.created_date = created_date;
}
public Date getUpdatedDate() {
return updated_date;
}
public void setUpdatedDate(Date updated_date) {
this.updated_date = updated_date;
}
I know this question has been brought up quite often, but so far I didn't really find an answer...
I am trying to use Android with GSON. I want to use a JSON String to fill a Gridview but I dont know how to access the nested objects.
The JSON File:
[{'ProductCategories':[
{
'name':'Cat1', 'Product Series':[
{
'name':'ProdSeries1', 'Description':'Lorem Ipsum Bla Bla','Products':[
{
'name':'Product1','key':'value','key':'...'
},
{
'name':'Product2','key':'value','key':'...'
},
]
}
]
},
]
}]
I made 4 classes:Products,ProductSeries,ProductCatalog and ProductCategory.
example:
public class ProductCatalog {
#SerializedName("ProductCategories")
#Expose
private List<ProductCategory> productCategories = null;
public List<ProductCategory> getProductCategories() {
return productCategories;
}
public void setProductCategories(List<ProductCategory> productCategories) {
this.productCategories = productCategories;
}
}
After that I parsed the JSON with gson:
Gson gson = new Gson();
Type type = new TypeToken<List<ProductCatalog>>(){}.getType();
List<ProductCatalog> productcatalog = gson.fromJson(JSONstring,type);
Now I have a parsed list of the JSON data but dont know how to work with the nested objects like 'Product1'. I thought the getters would help, but I cant access getProductCategories() in my activity. How can I do that?
If your using Gson means This will help you
public class MainClazz {
#SerializedName("ProductCategories")
#Expose
private List<ProductCategory> productCategories = null;
public List<ProductCategory> getProductCategories() {
return productCategories;
}
public void setProductCategories(List<ProductCategory> productCategories) {
this.productCategories = productCategories;
}
}
public class Product {
#SerializedName("name")
#Expose
private String name;
#SerializedName("key")
#Expose
private String key;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
}
public class ProductCategory {
#SerializedName("name")
#Expose
private String name;
#SerializedName("Product Series")
#Expose
private List<ProductSeries> productSeries = null;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<ProductSeries> getProductSeries() {
return productSeries;
}
public void setProductSeries(List<ProductSeries> productSeries) {
this.productSeries = productSeries;
}
}
public class ProductSeries {
#SerializedName("name")
#Expose
private String name;
#SerializedName("Description")
#Expose
private String description;
#SerializedName("Products")
#Expose
private List<Product> products = null;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public List<Product> getProducts() {
return products;
}
public void setProducts(List<Product> products) {
this.products = products;
}
}
I am working on deserializing the below JSON:
{"self":"http://members.cs.com/rest/api/user?username=abc#cs.com",
"key":"abc#cs.com",
"name":"abc#cs.com",
"emailAddress":"abc#cs.com",
"displayName":"ABC",
"active":true,
"members":{"size":1,"items":[{"name":"member-users","self":"http://members.cs.com/rest/api/user?username=abc#cs.com"}]},
"expand":"members"}
I have created the following classes:
#JsonIgnoreProperties(ignoreUnknown = true)
public class UserList {
private String name;
private String emailAddress;
private String displayName;
private boolean active;
List<MemberName> members = new ArrayList<>();
#JsonCreator
public UserList(#JsonProperty("name") String name, #JsonProperty("emailAddress") String emailAddress, #JsonProperty("displayName") String displayName, #JsonProperty("active") boolean active, #JsonProperty("members") List<MemberName> members) {
this.name = name;
this.emailAddress = emailAddress;
this.displayName = displayName;
this.active = active;
this.members.addAll(groups);
}
//getters
}
#JsonIgnoreProperties(ignoreUnknown = true)
public class MemberName {
private String name;
#JsonCreator
public MemberName(#JsonProperty("name") String name) {
this.name = name;
}
public String getName() {
return name;
}
}
When I don't give the members as a property the deserialization works fine and I can see the values for the name, displayName, active, emailAddress. The problem happens with the MemberName.
Could someone help with this?
This worked for me:
Class Items as below:
public class Items {
private String name;
private String self;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSelf() {
return self;
}
public void setSelf(String self) {
this.self = self;
}
}
Members class as below:
public class Members {
private int size;
private List<Items> items;
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public List<Items> getItems() {
return items;
}
public void setItems(List<Items> items) {
this.items = items;
}
}
Data class as below:
public class Data {
private String self;
private String key;
private String name;
private String emailAddress;
private String displayName;
private boolean active;
private Members members;
private String expand;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSelf() {
return self;
}
public void setSelf(String self) {
this.self = self;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public Members getMembers() {
return members;
}
public void setMembers(Members members) {
this.members = members;
}
public String getExpand() {
return expand;
}
public void setExpand(String expand) {
this.expand = expand;
}
}
The deserialization as below:
public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException {
String jsonString = "{\"self\": \"http://members.cs.com/rest/api/user?username=abc#cs.com\",\"key\": \"abc#cs.com\",\"name\": \"abc#cs.com\","
+ "\"emailAddress\": \"abc#cs.com\",\"displayName\": \"ABC\",\"active\": true,\"members\": {\"size\": 1,\"items\": [{"
+ "\"name\": \"member-users\",\"self\": \"http://members.cs.com/rest/api/user?username=abc#cs.com\" }]},\"expand\": \"members\"}";
ObjectMapper mapper = new ObjectMapper();
Data obj = mapper.readValue(jsonString,Data.class);
System.out.println(obj.getSelf());
System.out.println(obj.getKey());
System.out.println(obj.getName());
System.out.println(obj.getEmailAddress());
System.out.println(obj.getDisplayName());
System.out.println(obj.isActive());
System.out.println(obj.getMembers().getSize());
System.out.println(obj.getMembers().getItems().get(0).getName());
System.out.println(obj.getMembers().getItems().get(0).getSelf());
System.out.println(obj.getExpand());
}