org.frameworkset.json.Jackson1ObjectMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bboss-util Show documentation
Show all versions of bboss-util Show documentation
bboss is a j2ee framework include aop/ioc,mvc,persistent,taglib,rpc,event ,bean-xml serializable and so on.http://www.bbossgroups.com
package org.frameworkset.json;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Writer;
import java.lang.reflect.Type;
import org.codehaus.jackson.JsonParser.Feature;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
public class Jackson1ObjectMapper implements JacksonObjectMapper {
ObjectMapper mapper = new ObjectMapper();
/* (non-Javadoc)
* @see org.frameworkset.json.JacksonObjectMapper#json2Object(java.lang.String, java.lang.Class)
*/
@Override
public T json2Object(String jsonString,Class toclass) {
// TODO Auto-generated method stub
return json2Object(jsonString,toclass,true);
}
/* (non-Javadoc)
* @see org.frameworkset.json.JacksonObjectMapper#json2Object(java.lang.String, java.lang.Class, boolean)
*/
@Override
public T json2Object(String jsonString,Class toclass,boolean ALLOW_SINGLE_QUOTES) {
// TODO Auto-generated method stub
// String jsonString = "[{'from_date':'2001-09-21','to_date':'2011-04-02','company':'人寿保险','department':'xxx','position':'主管' },{'from_date':'0002-12-01','to_date':'2011-04-02', 'company':'人寿保险','department':'xxx','position':'主管' }]";
// ObjectMapper mapper = new ObjectMapper();
// mapper.configure(Feature.ALLOW_SINGLE_QUOTES, ALLOW_SINGLE_QUOTES);
try {
T value = mapper.readValue(jsonString, toclass);
return value;
} catch (Exception e) {
throw new IllegalArgumentException(jsonString,e);
}
}
/* (non-Javadoc)
* @see org.frameworkset.json.JacksonObjectMapper#json2Object(java.lang.String, java.lang.Class, boolean)
*/
@Override
public T json2Object(InputStream jsonString,Class toclass,boolean ALLOW_SINGLE_QUOTES) {
// TODO Auto-generated method stub
// String jsonString = "[{'from_date':'2001-09-21','to_date':'2011-04-02','company':'人寿保险','department':'xxx','position':'主管' },{'from_date':'0002-12-01','to_date':'2011-04-02', 'company':'人寿保险','department':'xxx','position':'主管' }]";
// ObjectMapper mapper = new ObjectMapper();
// mapper.configure(Feature.ALLOW_SINGLE_QUOTES, ALLOW_SINGLE_QUOTES);
try {
T value = mapper.readValue(jsonString, toclass);
return value;
} catch (Exception e) {
throw new IllegalArgumentException("",e);
}
}
// public T json2Object(String jsonString,TypeReference ref) {
// return json2Object(jsonString,ref,true);
//
//
// }
//
public T json2ObjectWithType(String jsonString,final JsonTypeReference ref,boolean ALLOW_SINGLE_QUOTES) {
// TODO Auto-generated method stub
// String jsonString = "[{'from_date':'2001-09-21','to_date':'2011-04-02','company':'人寿保险','department':'xxx','position':'主管' },{'from_date':'0002-12-01','to_date':'2011-04-02', 'company':'人寿保险','department':'xxx','position':'主管' }]";
ObjectMapper mapper = new ObjectMapper();
TypeReference> ref_ = new TypeReference
© 2015 - 2025 Weber Informatics LLC | Privacy Policy