Skip to content
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

Merged
merged 1 commit into from
Sep 14, 2019

Conversation

catalin-burcea
Copy link
Contributor

No description provided.

private XMLGregorianCalendar published;

public Book() {
}
Copy link
Contributor

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() {
}
Copy link
Contributor

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() {
}
Copy link
Contributor

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");
Copy link
Contributor

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) {
Copy link
Contributor

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();
Copy link
Contributor

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?

@ashleyfrieze ashleyfrieze merged commit 2a16590 into eugenp:master Sep 14, 2019
@catalin-burcea catalin-burcea deleted the BAEL-3221 branch October 22, 2019 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants