boonproject / boon

Simple opinionated Java for the novice to expert level Java Programmer. Low Ceremony. High Productivity.
http://richardhightower.github.io/site/Boon/Welcome.html
Apache License 2.0
520 stars 102 forks source link

can't convert abstract field from json #341

Open javamonkey79 opened 8 years ago

javamonkey79 commented 8 years ago

I have an object that I'm writing out with boon and trying to read back in. One of the fields is an abstract type and it appears boon can't figure it out:

CAUSE org.boon.Exceptions$SoftenedException :: Unable to convert 1206514800000 to ABSTRACT class javax.xml.datatype.XMLGregorianCalendar

ROOT CAUSE MESSAGE: Unable to convert 1206514800000 to ABSTRACT class javax.xml.datatype.XMLGregorianCalendar

When I run it again with jackson, there are no problems and it appears jackson is resolving the class to: org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl

Is there a workaround here? Is this a known issue?

RichardHightower commented 8 years ago

There is a flag in the builder/factory to output "class". Find the flag. Set it, and then Boon will always output the concrete class. It has to be able to figure out the concrete class to read the JSON string and convert it into a Java object. I try to avoid sending abstract classes so that I don't have to send out the fully qualified classname with the JSON. Also I think Jackson was more focused on providing a JSON version of some of the XML parsers. It probably has a lot better support for javax.xml.datatype... Boon is more about Java basic types List, String, Calendar, Date, Class, URI, etc. But I could add support for XMLGregorianCalendar and for things in the javax.xml.datatype package. We do support Calendar, Date, etc. So we could support

javax.xml.datatype
Duration 
XMLGregorianCalendar

We also need to support

LocalDateTime
OffsetTime
Period
DATE    LocalDate
TIME    LocalTime
TIMESTAMP   LocalDateTime
TIME WITH TIMEZONE  OffsetTime
TIMESTAMP WITH TIMEZONE OffsetDateTime

I can take a stab at XMLGregorianCalendar and Duration if you agree to be the beta tester.

javamonkey79 commented 8 years ago

Yeah, I’d love to try it out; I’ll test it out. We really love boon and have been using it in production in place of jackson for some time now.

— Shaun

On Thu, Oct 29, 2015 at 9:55 AM, Richard Hightower notifications@github.com wrote:

There is a flag in the builder/factory to output "class". Find the flag. Set it, and then Boon will always output the concrete class. It has to be able to figure out the concrete class to read the JSON string and convert it into a Java object. I try to avoid sending abstract classes so that I don't have to send out the fully qualified classname with the JSON. Also I think Jackson was more focused on providing a JSON version of some of the XML parsers. It probably has a lot better support for javax.xml.datatype... Boon is more about Java basic types List, String, Calendar, Date, Class, URI, etc. But I could add support for XMLGregorianCalendar and for things in the javax.xml.datatype package. We do support Calendar, Date, etc. So we could support

javax.xml.datatype
Duration 
XMLGregorianCalendar

We also need to support

LocalDateTime
OffsetTime
Period
DATE  LocalDate
TIME  LocalTime
TIMESTAMP LocalDateTime
TIME WITH TIMEZONE    OffsetTime
TIMESTAMP WITH TIMEZONE   OffsetDateTime

I can take a stab at XMLGregorianCalendar and Duration if you agree to be the beta tester.

Reply to this email directly or view it on GitHub: https://github.com/boonproject/boon/issues/341#issuecomment-152247622

RichardHightower commented 8 years ago

Ok. I will add it.

javamonkey79 commented 8 years ago

Just to be clear, the problem is on deserialization. The call to fromJson is what fails because the json data is a timestamp, but needs to get converted to the abstract Gregorian calendar type I mentioned before. On Nov 1, 2015 10:30 AM, "Richard Hightower" notifications@github.com wrote:

Ok. I will add it.

— Reply to this email directly or view it on GitHub https://github.com/boonproject/boon/issues/341#issuecomment-152850683.

RichardHightower commented 8 years ago

Sorry that I have not got to this yet.