Project

General

Profile

« Previous | Next » 

Revision e6044ca7

Added by Andreas Kohlbecker over 5 years ago

fix #7979 DateTimeJSONValueProcessor returns null for null

View differences:

cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/value/DateTimeJSONValueProcessor.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;
14

  
15 12
import org.apache.log4j.Logger;
16 13
import org.joda.time.DateTime;
17 14
import org.joda.time.format.DateTimeFormatter;
18 15
import org.joda.time.format.ISODateTimeFormat;
19 16

  
17
import net.sf.json.JsonConfig;
18
import net.sf.json.processors.JsonValueProcessor;
19

  
20 20
/**
21 21
 * @author n.hoffmann
22 22
 * @since 24.07.2008
......
27 27
			.getLogger(DateTimeJSONValueProcessor.class);
28 28

  
29 29
	private static DateTimeFormatter iso8601Format = ISODateTimeFormat.dateTime();
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
		DateTime dateTime = (DateTime) object;
36
        return DateTimeJSONValueProcessor.iso8601Format.print(dateTime);
37
        return formatDateTime(object);
37 38
	}
38 39

  
39 40
	/* (non-Javadoc)
40 41
	 * @see net.sf.json.processors.JsonValueProcessor#processObjectValue(java.lang.String, java.lang.Object, net.sf.json.JsonConfig)
41 42
	 */
42
	public Object processObjectValue(String key, Object object,
43
	@Override
44
    public Object processObjectValue(String key, Object object,
43 45
			JsonConfig jsonConfig) {
44
		DateTime dateTime = (DateTime) object;
45
        return DateTimeJSONValueProcessor.iso8601Format.print(dateTime);
46
	    return formatDateTime(object);
46 47
	}
48

  
49
    /**
50
     * @param object
51
     * @return
52
     */
53
    public Object formatDateTime(Object object) {
54
        if(object != null){
55
	        DateTime dateTime = (DateTime) object;
56
	        // WARNING! null means now!
57
	        return DateTimeJSONValueProcessor.iso8601Format.print(dateTime);
58
	    } else {
59
	        return null;
60
	    }
61
    }
47 62
}

Also available in: Unified diff