Revision f1a25720
Added by Katja Luther over 6 years ago
- ID f1a25720755daa96e8838a617a660dfced7b9f31
- Parent 23e50194
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/value/PartialJSONValueProcessor.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.cdm.remote.json.processor.value; |
11 | 11 |
|
12 |
import net.sf.json.JsonConfig;
|
|
13 |
import net.sf.json.processors.JsonValueProcessor;
|
|
12 |
import java.time.LocalDate;
|
|
13 |
import java.time.format.DateTimeFormatter;
|
|
14 | 14 |
|
15 | 15 |
import org.apache.log4j.Logger; |
16 |
import org.joda.time.Partial; |
|
17 |
import org.joda.time.format.ISODateTimeFormat; |
|
18 | 16 |
|
19 | 17 |
import eu.etaxonomy.cdm.hibernate.PartialUserType; |
18 |
import net.sf.json.JsonConfig; |
|
19 |
import net.sf.json.processors.JsonValueProcessor; |
|
20 | 20 |
|
21 | 21 |
/** |
22 | 22 |
* Partial time as four digit year, two digit month of year, and two digit day of month (yyyy-MM-dd). |
... | ... | |
27 | 27 |
public class PartialJSONValueProcessor implements JsonValueProcessor { |
28 | 28 |
private static Logger logger = Logger.getLogger(PartialJSONValueProcessor.class); |
29 | 29 |
|
30 |
|
|
30 |
|
|
31 | 31 |
/* (non-Javadoc) |
32 | 32 |
* @see net.sf.json.processors.JsonValueProcessor#processArrayValue(java.lang.Object, net.sf.json.JsonConfig) |
33 | 33 |
*/ |
34 |
public Object processArrayValue(Object object, JsonConfig jsonConfig) { |
|
34 |
@Override |
|
35 |
public Object processArrayValue(Object object, JsonConfig jsonConfig) { |
|
35 | 36 |
if(object == null){ |
36 | 37 |
return ""; |
37 | 38 |
} |
38 |
Partial partial = (Partial) object;
|
|
39 |
LocalDate partial = (LocalDate) object;
|
|
39 | 40 |
if (logger.isDebugEnabled()) { |
40 |
logger.debug("processArrayValue of joda.time.DateTime: " + PartialUserType.partialToString(partial));
|
|
41 |
logger.debug("processArrayValue of ZonedDateTime: " + PartialUserType.partialToString(partial));
|
|
41 | 42 |
} |
42 |
return partial.toString(ISODateTimeFormat.date());
|
|
43 |
return partial.format(DateTimeFormatter.ISO_DATE_TIME);
|
|
43 | 44 |
} |
44 | 45 |
|
45 | 46 |
/* (non-Javadoc) |
46 | 47 |
* @see net.sf.json.processors.JsonValueProcessor#processObjectValue(java.lang.String, java.lang.Object, net.sf.json.JsonConfig) |
47 | 48 |
*/ |
48 |
public Object processObjectValue(String key, Object object, JsonConfig jsonConfig) { |
|
49 |
@Override |
|
50 |
public Object processObjectValue(String key, Object object, JsonConfig jsonConfig) { |
|
49 | 51 |
if(object == null){ |
50 | 52 |
return ""; |
51 | 53 |
} |
52 |
Partial partial = (Partial) object;
|
|
54 |
LocalDate partial = (LocalDate) object;
|
|
53 | 55 |
if (logger.isDebugEnabled()) { |
54 |
logger.debug("processObjectValue of joda.time.DateTime: " + PartialUserType.partialToString(partial));
|
|
56 |
logger.debug("processObjectValue of java.time.ZonedDateTime: " + PartialUserType.partialToString(partial));
|
|
55 | 57 |
} |
56 |
return partial.toString(ISODateTimeFormat.date());
|
|
58 |
return partial.format(DateTimeFormatter.ISO_DATE_TIME);
|
|
57 | 59 |
} |
58 | 60 |
} |
Also available in: Unified diff
first implementation for change from joda time to java8 time