I have a grails app that sends xml generated from Java POJOs through a REST like API.
On the client side there is a Java client that uses the same Java POJOs (the same jar library is used in Grails and the Java client) created from the XML.
For some reason the date in the XML doesn't get to the Java POJO. How do I get it in? Is there some trick I'm missing? Grails gets the date from the database (the column is a timestamp type), the XML has the date and time, the POJO has type Date
, but the getter for the time returns null
on the client side.
Here's the POJO code:
@Entity
@Table(name = "MODEL_VIEW")
@XmlRootElement
public class Model implements Serializable {
private static final long serialVersionUID = 1L;
@Basic(optional = false)
@Column(name = "MODEL_ID")
@Id
private BigInteger modelId;
@Column(name = "LAST_MODIFIED")
@Temporal(TemporalType.TIMESTAMP)
private Date lastModified;
public Model() {
}
public BigInteger getModelId() {
return modelId;
}
public void setModelId(BigInteger modelId) {
this.modelId = modelId;
}
public Date getLastModified() {
return lastModified;
}
public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}
}
UPDATE
Here is the XML (generated by Grails, using the same Entity classes, described above, as the client):
<?xml version="1.0" encoding="UTF-8"?>
<list>
<model id="1046">
<modelId>1046</modelId>
<lastModified>2013-09-17 17:42:17.478 PDT</lastModified>
</model>
Here is the code on the client that creates the POJO from the XML:
public synchronized List<Model> getAllModels() {
return targetModel.request(MEDIA_TYPE).get(new GenericType<List<Model>>(){});
}
// psuedo code that creates the "targetModel" object
private final static String BASE_URL ="http://mybiz.com/myapp";
private Client client = ClientBuilder.newClient();
client.register(new HttpBasicAuthFilter(username,password));
private WebTarget targetBase = client.target(BASE_URL);
private WebTarget targetModel = targetBase.path("model");
This is using Java EE 7 and Jersey client 2.0