-
Notifications
You must be signed in to change notification settings - Fork 54.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BAEL-3221] unmarshalling dates using JAXB - examples #7672
Conversation
83785b1
to
c97d364
Compare
private XMLGregorianCalendar published; | ||
|
||
public Book() { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this constructor? There are no other constructors, so you get the default one for free.
private Date published; | ||
|
||
public Book2() { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same point as above
private LocalDateTime published; | ||
|
||
public Book3() { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and again :)
|
||
public class DateAdapter extends XmlAdapter<String, Date> { | ||
|
||
private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be static
and have a BLOCK CAPITAL name.
|
||
@Override | ||
public String marshal(Date v) { | ||
synchronized (dateFormat) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate that this is not threadsafe... would it be safer/simpler to make the yyyy-MM-dd...
the private static final
thing and create a new SimpleDateFormat
object every time?
System.out.println(book2); | ||
System.out.println(book3); | ||
} catch (JAXBException e) { | ||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is IDE generated code... could we avoid the try/catch here and just let main
throw an Exception?
Or would be better illustrating all this using unit tests, rather than a main method?
c97d364
to
73e45ac
Compare
73e45ac
to
b7e8325
Compare
No description provided.