5

I have a tomee server and from android i can call GET methods and works well. Now i try to POST with volley library an entity which has a field java.util.Date but in server i get:

WARNING - Interceptor for     {http://services.scol.csd.gr/}MeasureinfoFacadeREST has thrown exception,     unwinding now
org.apache.johnzon.mapper.MapperException: java.text.ParseException: Unparseable date: "Sep 23, 2016 13:14:29"

WARNING - Exception in handleFault on interceptor org.apache.cxf.jaxrs.interceptor.JAXRSDefaultFaultOutInterceptor@60d6a046
org.apache.cxf.interceptor.Fault: java.text.ParseException: Unparseable date: "Sep 23, 2016 13:46:36"

Caused by: java.text.ParseException: Unparseable date: "Sep 23, 2016 13:14:29"
    at java.text.DateFormat.parse(DateFormat.java:366)
    at org.apache.johnzon.mapper.converter.DateConverter.fromString(DateConverter.java:49)
    ... 48 more

I tried to override johnzon converter like:

in resources.xml:

<?xml version="1.0"?>
<resources>
  <Service id="johnzon" class-name="org.apache.johnzon.jaxrs.ConfigurableJohnzonProvider">
    accessModeName = field
  </Service>
</resources>

in openejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar>
  <pojo-deployment class-name="test">
    <properties>
      cxf.jaxrs.skip-provider-scanning = true
      cxf.jaxrs.providers = johnzon,org.apache.openejb.server.cxf.rs.EJBAccessExceptionMapper
    </properties>
  </pojo-deployment>
</openejb-jar>

in pojo-deployment i give a random name like 'test'

public class LocalDateConverter implements Converter<Date> {
    @Override
    public String toString(final Date instance) {
        final Calendar cal = GregorianCalendar.getInstance();
        cal.setTime(instance);
        return DatatypeConverter.printDateTime(cal);
    }

    @Override
    public Date fromString(final String text) {
        return DatatypeConverter.parseDateTime(text).getTime();
    }
}

and then in my entity:

@JohnzonConverter(LocalDateConverter.class)
public Date getDay() {
    return day;
}

@JohnzonConverter(LocalDateConverter.class)
public void setDay(Date day) {
    this.day = day;
}

I found this configuration from here

but the problem remains.

Any suggestions?

ddarellis
  • 3,912
  • 3
  • 25
  • 53

1 Answers1

1
accessModeName = field

so

@JohnzonConverter(LocalDateConverter.class)

goes on the field ;)

Romain Manni-Bucau
  • 3,354
  • 1
  • 16
  • 13
  • https://github.com/apache/johnzon/blob/982af7173b1596134c6ed9ce43d871863f58e285/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/converter/TimestampAdapterTest.java is almost exactly what you do excepted the format is different wonder if it can be that you use on an older release? – Romain Manni-Bucau Sep 23 '16 at 11:51