1
|
/**
|
2
|
* Copyright (C) 2009 EDIT European Distributed Institute of Taxonomy
|
3
|
* http://www.e-taxonomy.eu
|
4
|
*
|
5
|
* The contents of this file are subject to the Mozilla Public License Version
|
6
|
* 1.1 See LICENSE.TXT at the top of this package for the full license terms.
|
7
|
*/
|
8
|
|
9
|
package eu.etaxonomy.cdm.remote.json.processor.value;
|
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.log4j.Logger;
|
16
|
|
17
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
18
|
import eu.etaxonomy.cdm.remote.json.processor.matcher.HibernateJSONValueProcessorMatcher;
|
19
|
|
20
|
/**
|
21
|
* Used in conjunction with the {@link HibernateJSONValueProcessorMatcher} to unwrap
|
22
|
* beans from hibernate proxies. Using this Value processor is essential for
|
23
|
* properly detecting @Transient annotations which are not inherited by subclasses
|
24
|
* like the proxies
|
25
|
*
|
26
|
* @author a.kohlbecker
|
27
|
*/
|
28
|
public class HibernateJSONValueProcessor implements JsonValueProcessor {
|
29
|
|
30
|
public static final Logger logger = Logger.getLogger(HibernateJSONValueProcessor.class);
|
31
|
|
32
|
// public Object processArrayValue(Object object, JsonConfig jsonConfig) {
|
33
|
// if(Hibernate.isInitialized(object)) {
|
34
|
// log.debug("Processing array value " + object);
|
35
|
// return JSONArray.fromObject(object,jsonConfig);
|
36
|
// } else{
|
37
|
// log.debug("Collection is uninitialized, returning null");
|
38
|
// return JSONNull.getInstance();
|
39
|
// }
|
40
|
// }
|
41
|
|
42
|
public Object processArrayValue(Object object, JsonConfig jsonConfig) {
|
43
|
// usage of the InitializedHibernatePropertyFiler is expected !!!
|
44
|
// retain default processing
|
45
|
return JSONArray.fromObject(object,jsonConfig);
|
46
|
}
|
47
|
|
48
|
|
49
|
public Object processObjectValue(String propertyName, Object object, JsonConfig jsonConfig) {
|
50
|
// deproxy
|
51
|
Object target = HibernateProxyHelper.deproxy(object, Object.class);
|
52
|
if(logger.isDebugEnabled()){
|
53
|
logger.debug("deproxying object " + target);
|
54
|
}
|
55
|
return target;
|
56
|
|
57
|
}
|
58
|
|
59
|
}
|