Revision f0b8034c
Added by Andreas Müller over 1 year ago
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/value/HibernateJSONValueProcessor.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2009 EDIT European Distributed Institute of Taxonomy |
3 | 3 |
* http://www.e-taxonomy.eu |
4 |
*
|
|
4 |
* |
|
5 | 5 |
* The contents of this file are subject to the Mozilla Public License Version |
6 | 6 |
* 1.1 See LICENSE.TXT at the top of this package for the full license terms. |
7 | 7 |
*/ |
8 | 8 |
|
9 | 9 |
package eu.etaxonomy.cdm.remote.json.processor.value; |
10 | 10 |
|
11 |
import net.sf.json.JSONArray; |
|
12 |
import net.sf.json.JsonConfig; |
|
13 |
import net.sf.json.processors.JsonValueProcessor; |
|
14 |
|
|
15 |
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger; |
|
11 |
import org.apache.logging.log4j.LogManager; |
|
12 |
import org.apache.logging.log4j.Logger; |
|
16 | 13 |
|
17 | 14 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
18 | 15 |
import eu.etaxonomy.cdm.remote.json.processor.matcher.HibernateJSONValueProcessorMatcher; |
16 |
import net.sf.json.JSONArray; |
|
17 |
import net.sf.json.JsonConfig; |
|
18 |
import net.sf.json.processors.JsonValueProcessor; |
|
19 | 19 |
|
20 | 20 |
/** |
21 | 21 |
* Used in conjunction with the {@link HibernateJSONValueProcessorMatcher} to unwrap |
22 | 22 |
* beans from hibernate proxies. Using this Value processor is essential for |
23 | 23 |
* properly detecting @Transient annotations which are not inherited by subclasses |
24 | 24 |
* like the proxies |
25 |
*
|
|
25 |
* |
|
26 | 26 |
* @author a.kohlbecker |
27 | 27 |
*/ |
28 | 28 |
public class HibernateJSONValueProcessor implements JsonValueProcessor { |
29 |
|
|
29 |
|
|
30 | 30 |
public static final Logger logger = LogManager.getLogger(HibernateJSONValueProcessor.class); |
31 |
|
|
31 |
|
|
32 | 32 |
// public Object processArrayValue(Object object, JsonConfig jsonConfig) { |
33 | 33 |
// if(Hibernate.isInitialized(object)) { |
34 | 34 |
// log.debug("Processing array value " + object); |
... | ... | |
38 | 38 |
// return JSONNull.getInstance(); |
39 | 39 |
// } |
40 | 40 |
// } |
41 |
|
|
42 |
public Object processArrayValue(Object object, JsonConfig jsonConfig) { |
|
41 |
|
|
42 |
@Override |
|
43 |
public Object processArrayValue(Object object, JsonConfig jsonConfig) { |
|
43 | 44 |
// usage of the InitializedHibernatePropertyFiler is expected !!! |
44 | 45 |
// retain default processing |
45 | 46 |
return JSONArray.fromObject(object,jsonConfig); |
46 | 47 |
} |
47 |
|
|
48 | 48 |
|
49 |
public Object processObjectValue(String propertyName, Object object, JsonConfig jsonConfig) { |
|
49 |
@Override |
|
50 |
public Object processObjectValue(String propertyName, Object object, JsonConfig jsonConfig) { |
|
50 | 51 |
// deproxy |
51 | 52 |
Object target = HibernateProxyHelper.deproxy(object, Object.class); |
52 | 53 |
if(logger.isDebugEnabled()){ |
53 | 54 |
logger.debug("deproxying object " + target); |
54 | 55 |
} |
55 | 56 |
return target; |
56 |
|
|
57 |
} |
|
58 | 57 |
|
59 |
} |
|
58 |
} |
|
59 |
} |
Also available in: Unified diff
cleanup