Hi is User part of a webservice signature or referenced through a @XmlSeeAlso? If not then it is not passed to the JAXBContext creation.
Romain Manni-Bucau @rmannibucau | Blog | Old Blog | Github | LinkedIn 2017-11-02 15:15 GMT+01:00 Alinezhad.a <[email protected]>: > Hi > > i'm get confused why this simple code not working, i have this simple class > > @Entity > @Table(name = "users") > @XmlRootElement(name = "user") > @XmlAccessorType(XmlAccessType.FIELD) > public class User implements Serializable { > > @Id > @GeneratedValue(strategy = GenerationType.AUTO) > @Column(name = "id") > protected Long id; > > @NotNull > @Size(min = 3, max = 100, message = "{invalid.fullName}") > @Column(name = "full_name", nullable = false, length = 100) > @XmlElement(name = "fullName") > private String fullName; > > @Temporal(TemporalType.TIMESTAMP) > @Column(name = "last_login_date") > @XmlElement(name = "lastLoginDate") > @XmlJavaTypeAdapter(DateFormatterAdapter.class) > private Date lastLoginDate; > > public Long getId() { return id;} > > public void setId(Long id) { this.id = id; } > > public String getFullName() { return fullName; } > > public void setFullName(String fullName) { this.fullName = fullName; } > > public Date getLastLoginDate() { return lastLoginDate; } > > public void setLastLoginDate(Date lastLoginDate) { > this.lastLoginDate = lastLoginDate; > } > > public User() { } > > } > > and this simple XmlAdapter as follow > > public class DateFormatterAdapter extends XmlAdapter<String, Date> { > > public DateFormatterAdapter() { } > > @Override > public Date unmarshal(String v) throws Exception { > return new Date(Long.parseLong(v)); > } > > @Override > public String marshal(Date v) throws Exception { > return ((Long) v.getTime()).toString(); > } > } > and a jersey restful service that return list of users as APPLICATION_JSON, > in this scenario every things is ok, but DateFormatterAdapter class not been > called and lastLoginDate not formatted as desired in result. > > but when i am doing this as follow manually,every things is Ok > > JAXBContext jc = JAXBContext.newInstance(User.class); > > Unmarshaller unmarshaller = jc.createUnmarshaller(); > File xml = new File("e:/input.xml"); > User foo = (User) unmarshaller.unmarshal(xml); > foo.setLastLoginDate(new Date()); > > Marshaller marshaller = jc.createMarshaller(); > marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); > marshaller.marshal(foo, System.out); > > i am using tomee 7.0.2 as my application server and eclipselink-2.7.0 > > > > > > -- > Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Dev-f982480.html
