Sorry for what it seems to be a redundant question but i do have many options, and despite my effort reading dozen of threads, i'm not able to understand what to do.
I do have a java application which job is to :
- get datas from a SOAP WS (XML),
- do some logic ( incoming deliverydate will become datebl )
- Finally send it to a REST WS (JSON Format), which will update an Oracle Table
Plan is thus as follows :
SOAP WS ---- deliverydate ----> JAVA APP (logic) ---- datebl ----> REST WS
Jar used in JAVA APP are jackson-core-asl-1.9.13.jar
and jackson-mapper-asl-1.9.13.jar
among others.
Issues i have is when dealing with dates.
Readings : ( Tried to be inspired but jackson version seems not to be the same ) :
Jackson 2.3.2: Issue with deserializing a Date despite of setting the date format to ObjectMapper
Edit 01/04/15
http://jackson-users.ning.com/forum/topics/cannot-deserialize-a-date
The facts now
Point 1 : When recovering data from SOAP WS, deliverydate is a String which exact value is :
2014-07-31 07:00:00.0
Point 2: Just before using the setter, i thought it could be a good idea to format this String to a date.
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dateebl = dateFormat.parse(deliverydate);
msi.setDatebl(dateebl);
datebl declaration in POJO
private java.util.Date datebl;
At this stage, datebl value has transformed to
Thu Jul 31 07:00:00 CEST 2014
(despite choosing the specific format yyyy-MM-dd HH:mm:ss)
Point 3 and ERROR i have : The error i have is thrown by the rest server:
Can not construct instance of java.util.Date from String value 'Thu Jul 31 07:00:00 CEST 2014': not a valid representation (error: Can not parse date "Thu Jul 31 07:00:00 CEST 2014": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd")) at [Source: org.glassfish.jersey.message.internal.EntityInputStream@5709779; line: 1, column: 74] (through reference chain: com.rest.entities.MvtSwapsIn["datebl"])
What i tried to do : To resolve this, as i'm using a version prior to 2.x, i thought that my best option was to use a custom serializer, so :
In pojo, annotation was added just before the getter
@JsonSerialize(using = CustomJsonDateSerializer.class) public java.util.Date getDatebl() { return datebl; }
Serializer was created as follows
public class CustomJsonDateSerializer extends JsonSerializer<Date> { @Override public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { SimpleDateFormat dateFormat = new SimpleDateFormat(Properties.General.FORMAT_HEURE_JSON_SERIALIZE_2); String dateString = dateFormat.format(value); jgen.writeString(dateString); }
}
In example,tried with FORMAT_HEURE_JSON_SERIALIZE_2, but tried many others without success.
public static final String FORMAT_HEURE_JSON = new String("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
public static final String FORMAT_HEURE_JSON_SERIALIZE = new String("EEE yyyy-MM-dd'T'HH:mm:ss.SSSZ");
public static final String FORMAT_HEURE_JSON_SERIALIZE_2 = new String("EEE, dd MMM yyyy HH:mm:ss zzz");
public static final String FORMAT_HEURE_JSON_SERIALIZE_3 = new String("yyyy-MM-dd HH:mm:ss");
At this point, i'm lost.
I don't know where and how to update my code.
- Should i still use SimpleDateFormat after getting date from SOAP ws ?
- Given the fact i'm using jackson 1.9, is my @JsonSerialize annotation good ? ( as well as the serializer ?)
- Do i have to modify something on the rest server ?
Please can someone help me organize my thoughts ?
Kind regards,
Pierre