Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置

时间:2020-12-09 08:28:53

The following code examples are extracted from open source projects. You can click Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置 to vote up the examples that are useful to you.

Example 1

From project rest-support, under directory /hudson-rest-common/src/main/java/org/hudsonci/rest/common/.

Source file: ObjectMapperProvider.java

  19 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
public ObjectMapperProvider(){
final ObjectMapper mapper=new ObjectMapper();
DeserializationConfig dconfig=mapper.getDeserializationConfig();
dconfig.setAnnotationIntrospector(new JacksonAnnotationIntrospector());
SerializationConfig sconfig=mapper.getSerializationConfig();
sconfig.setAnnotationIntrospector(new JacksonAnnotationIntrospector());
sconfig.setSerializationInclusion(NON_NULL);
mapper.configure(WRITE_DATES_AS_TIMESTAMPS,false);
mapper.configure(AUTO_DETECT_IS_GETTERS,false);
mapper.configure(AUTO_DETECT_GETTERS,false);
mapper.configure(AUTO_DETECT_SETTERS,false);
this.mapper=mapper;
}
 

Example 2

From project sisu-goodies, under directory/marshal/src/main/java/org/sonatype/sisu/goodies/marshal/internal/jackson/.

Source file: ObjectMapperProvider.java

  18 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
public ObjectMapperProvider(){
final ObjectMapper mapper=new ObjectMapper();
DeserializationConfig dconfig=mapper.getDeserializationConfig();
dconfig.withAnnotationIntrospector(new JacksonAnnotationIntrospector());
SerializationConfig sconfig=mapper.getSerializationConfig();
sconfig.withAnnotationIntrospector(new JacksonAnnotationIntrospector());
sconfig.setSerializationInclusion(NON_NULL);
mapper.configure(WRITE_DATES_AS_TIMESTAMPS,false);
mapper.configure(INDENT_OUTPUT,true);
this.mapper=mapper;
}
 

Example 3

From project ANNIS, under directory /annis-service/src/main/java/annis/.

Source file: AnnisRunner.java

  17 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
public void doAnnotations(String doListValues){
boolean listValues="values".equals(doListValues);
List<AnnisAttribute> annotations=annisDao.listAnnotations(getCorpusList(),listValues,true);
try {
ObjectMapper om=new ObjectMapper();
AnnotationIntrospector ai=new JaxbAnnotationIntrospector();
DeserializationConfig config=om.getDeserializationConfig().withAnnotationIntrospector(ai);
om.setDeserializationConfig(config);
om.configure(SerializationConfig.Feature.INDENT_OUTPUT,true);
System.out.println(om.writeValueAsString(annotations));
}
catch ( IOException ex) {
log.error("problems with writing result",ex);
}
}
 

Example 4

From project MailJimp, under directory /mailjimp-core/src/main/java/mailjimp/service/impl/.

Source file: MailJimpJsonService.java

  17 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
@PostConstruct public void init(){
checkConfig();
log.info("Creating MailChimp integration client.");
String url=buildServerURL();
log.info("Server URL is: {}",url);
client=Client.create();
resource=client.resource(url);
SerializationConfig s=m.getSerializationConfig();
s.setSerializationInclusion(Inclusion.NON_NULL);
s.withDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
m.setSerializationConfig(s);
DeserializationConfig d=m.getDeserializationConfig();
d.withDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
m.setDeserializationConfig(d);
m.setDateFormat(new SimpleDateFormat("yyyy-MM-MM HH:mm:ss"));
}

Example 5

From project airlift, under directory /json/src/main/java/io/airlift/json/.

Source file: ObjectMapperProvider.java

  15 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
@Override public ObjectMapper get(){
ObjectMapper objectMapper=new ObjectMapper();
objectMapper.getDeserializationConfig().disable(FAIL_ON_UNKNOWN_PROPERTIES);
objectMapper.getSerializationConfig().disable(WRITE_DATES_AS_TIMESTAMPS);
objectMapper.getSerializationConfig().setSerializationInclusion(NON_NULL);
objectMapper.getDeserializationConfig().disable(DeserializationConfig.Feature.AUTO_DETECT_FIELDS);
objectMapper.getDeserializationConfig().disable(AUTO_DETECT_SETTERS);
objectMapper.getSerializationConfig().disable(SerializationConfig.Feature.AUTO_DETECT_FIELDS);
objectMapper.getSerializationConfig().disable(AUTO_DETECT_GETTERS);
objectMapper.getSerializationConfig().disable(AUTO_DETECT_IS_GETTERS);
if (jsonSerializers != null || jsonDeserializers != null || keySerializers != null || keyDeserializers != null) {
SimpleModule module=new SimpleModule(getClass().getName(),new Version(1,0,0,null));
if (jsonSerializers != null) {
for ( Entry<Class<?>,JsonSerializer<?>> entry : jsonSerializers.entrySet()) {
addSerializer(module,entry.getKey(),entry.getValue());
}
}
if (jsonDeserializers != null) {
for ( Entry<Class<?>,JsonDeserializer<?>> entry : jsonDeserializers.entrySet()) {
addDeserializer(module,entry.getKey(),entry.getValue());
}
}
if (keySerializers != null) {
for ( Entry<Class<?>,JsonSerializer<?>> entry : keySerializers.entrySet()) {
addKeySerializer(module,entry.getKey(),entry.getValue());
}
}
if (keyDeserializers != null) {
for ( Entry<Class<?>,KeyDeserializer> entry : keyDeserializers.entrySet()) {
module.addKeyDeserializer(entry.getKey(),entry.getValue());
}
}
objectMapper.registerModule(module);
}
return objectMapper;
}

Example 6

From project AutobahnAndroid, under directory /Autobahn/src/de/tavendo/autobahn/.

Source file: WampReader.java

  15 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
/**
* A reader object is created in AutobahnConnection.
* @param calls The call map created on master.
* @param subs The event subscription map created on master.
* @param master Message handler of master (used by us to notify the master).
* @param socket The TCP socket.
* @param options WebSockets connection options.
* @param threadName The thread name we announce.
*/
public WampReader(ConcurrentHashMap<String,CallMeta> calls,ConcurrentHashMap<String,SubMeta> subs,Handler master,SocketChannel socket,WebSocketOptions options,String threadName){
super(master,socket,options,threadName);
mCalls=calls;
mSubs=subs;
mJsonMapper=new ObjectMapper();
mJsonMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES,false);
mJsonFactory=mJsonMapper.getJsonFactory();
if (DEBUG) Log.d(TAG,"created");
}

Example 7

From project build-info, under directory /build-info-extractor/src/main/java/org/jfrog/build/extractor/.

Source file: BuildInfoExtractorUtils.java

  15 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
private static JsonFactory createJsonFactory(){
JsonFactory jsonFactory=new JsonFactory();
ObjectMapper mapper=new ObjectMapper(jsonFactory);
mapper.getSerializationConfig().setAnnotationIntrospector(new JacksonAnnotationIntrospector());
mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
mapper.getDeserializationConfig().disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
jsonFactory.setCodec(mapper);
return jsonFactory;
}

Example 8

From project candlepin, under directory /src/main/java/org/candlepin/sync/.

Source file: SyncUtils.java

  15 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
static ObjectMapper getObjectMapper(Config config){
ObjectMapper mapper=new ObjectMapper();
AnnotationIntrospector primary=new JacksonAnnotationIntrospector();
AnnotationIntrospector secondary=new JaxbAnnotationIntrospector();
AnnotationIntrospector pair=new AnnotationIntrospector.Pair(primary,secondary);
mapper.setAnnotationIntrospector(pair);
mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS,false);
SimpleFilterProvider filterProvider=new SimpleFilterProvider();
filterProvider.setDefaultFilter(new ExportBeanPropertyFilter());
mapper.setFilters(filterProvider);
if (config != null) {
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES,config.failOnUnknownImportProperties());
}
return mapper;
}

Example 9

From project components-ness-jackson, under directory /src/main/java/com/nesscomputing/jackson/.

Source file: MapEntryModule.java

  15 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
@Override public JsonDeserializer<?> findBeanDeserializer(JavaType type,DeserializationConfig config,DeserializerProvider provider,BeanDescription beanDesc,BeanProperty property) throws JsonMappingException {
if (type.getRawClass().equals(Map.Entry.class)) {
return new MapEntryDeserializer(type,property);
}
return null;
}

Example 10

From project crest, under directory /core/src/main/java/org/codegist/crest/serializer/jackson/.

Source file: JacksonFactory.java

  15 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
static ObjectMapper createObjectMapper(CRestConfig crestConfig,Class<?> source){
String prefix=source.getName();
ObjectMapper mapper=crestConfig.get(prefix + JACKSON_OBJECT_MAPPER);
if (mapper != null) {
return mapper;
}
mapper=new ObjectMapper();
Map<DeserializationConfig.Feature,Boolean> deserConfig=crestConfig.get(prefix + JACKSON_DESERIALIZER_CONFIG,DEFAULT_DESERIALIZER_CONFIG);
for ( Map.Entry<DeserializationConfig.Feature,Boolean> feature : deserConfig.entrySet()) {
mapper.configure(feature.getKey(),feature.getValue());
}
Map<SerializationConfig.Feature,Boolean> serConfig=crestConfig.get(prefix + JACKSON_SERIALIZER_CONFIG,DEFAULT_SERIALIZER_CONFIG);
for ( Map.Entry<SerializationConfig.Feature,Boolean> feature : serConfig.entrySet()) {
mapper.configure(feature.getKey(),feature.getValue());
}
return mapper;
}

Example 11

From project Faye-Android, under directory /src/com/b3rwynmobile/fayeclient/autobahn/.

Source file: WampReader.java

  15 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
/**
* A reader object is created in AutobahnConnection.
* @param calls The call map created on master.
* @param subs The event subscription map created on master.
* @param master Message handler of master (used by us to notify the master).
* @param socket The TCP socket.
* @param options WebSockets connection options.
* @param threadName The thread name we announce.
*/
public WampReader(ConcurrentHashMap<String,CallMeta> calls,ConcurrentHashMap<String,SubMeta> subs,Handler master,SocketChannel socket,WebSocketOptions options,String threadName){
super(master,socket,options,threadName);
mCalls=calls;
mSubs=subs;
mJsonMapper=new ObjectMapper();
mJsonMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES,false);
mJsonFactory=mJsonMapper.getJsonFactory();
if (DEBUG) Log.d(TAG,"created");
}

Example 12

From project geolatte-common, under directory /src/test/java/org/geolatte/common/dataformats/json/.

Source file: GeoJsonToDeserializationTest.java

  15 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
@BeforeClass public static void setupSuite(){
assembler=new GeoJsonToAssembler();
mapper=new ObjectMapper();
JacksonConfiguration.applyMixin(mapper);
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES,false);
}

Example 13

From project gnip4j, under directory /core/src/main/java/com/zaubersoftware/gnip4j/api/impl/.

Source file: DefaultGnipStream.java

  15 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
public static final ObjectMapper getObjectMapper(){
final ObjectMapper mapper=new ObjectMapper();
SimpleModule gnipActivityModule=new SimpleModule("gnip.activity",new Version(1,0,0,null));
gnipActivityModule.addDeserializer(Geo.class,new GeoDeserializer(Geo.class));
mapper.registerModule(gnipActivityModule);
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES,false);
return mapper;
}

Example 14

From project jetty-session-redis, under directory /src/main/java/com/ovea/jetty/session/serializer/.

Source file: JsonSerializer.java

  15 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
@Override public void start(){
mapper=new ObjectMapper();
mapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE,false);
mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT,false);
mapper.configure(SerializationConfig.Feature.AUTO_DETECT_GETTERS,false);
mapper.configure(SerializationConfig.Feature.AUTO_DETECT_IS_GETTERS,false);
mapper.configure(SerializationConfig.Feature.AUTO_DETECT_FIELDS,true);
mapper.configure(SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS,true);
mapper.configure(SerializationConfig.Feature.USE_STATIC_TYPING,false);
mapper.configure(SerializationConfig.Feature.WRITE_ENUMS_USING_TO_STRING,false);
mapper.configure(SerializationConfig.Feature.SORT_PROPERTIES_ALPHABETICALLY,true);
mapper.configure(SerializationConfig.Feature.USE_ANNOTATIONS,true);
mapper.configure(DeserializationConfig.Feature.USE_ANNOTATIONS,true);
mapper.configure(DeserializationConfig.Feature.AUTO_DETECT_SETTERS,false);
mapper.configure(DeserializationConfig.Feature.AUTO_DETECT_CREATORS,true);
mapper.configure(DeserializationConfig.Feature.AUTO_DETECT_FIELDS,true);
mapper.configure(DeserializationConfig.Feature.USE_GETTERS_AS_SETTERS,false);
mapper.configure(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS,true);
mapper.configure(DeserializationConfig.Feature.READ_ENUMS_USING_TO_STRING,true);
mapper.setVisibilityChecker(new VisibilityChecker.Std(ANY,ANY,ANY,ANY,ANY));
super.start();
}

Example 15

From project mongo-jackson-mapper, under directory /src/main/java/net/vz/mongodb/jackson/internal/.

Source file: MongoJacksonDeserializers.java

  15 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
public JsonDeserializer<?> findBeanDeserializer(JavaType type,DeserializationConfig config,DeserializerProvider provider,BeanDescription beanDesc,BeanProperty property) throws JsonMappingException {
if (type.getRawClass() == DBRef.class) {
if (!type.hasGenericTypes()) {
throw new JsonMappingException("Property " + property + " doesn't declare object and key type");
}
JavaType objectType=type.containedType(0);
JavaType keyType=type.containedType(1);
return new DBRefDeserializer(objectType,keyType);
}
return super.findBeanDeserializer(type,config,provider,beanDesc,property);
}

Example 16

From project platform_3, under directory /json/src/main/java/com/proofpoint/json/.

Source file: ObjectMapperProvider.java

  15 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
@Override public ObjectMapper get(){
ObjectMapper objectMapper=new ObjectMapper();
objectMapper.getDeserializationConfig().disable(FAIL_ON_UNKNOWN_PROPERTIES);
objectMapper.getSerializationConfig().disable(WRITE_DATES_AS_TIMESTAMPS);
objectMapper.getSerializationConfig().setSerializationInclusion(NON_NULL);
objectMapper.getDeserializationConfig().disable(DeserializationConfig.Feature.AUTO_DETECT_FIELDS);
objectMapper.getDeserializationConfig().disable(AUTO_DETECT_SETTERS);
objectMapper.getSerializationConfig().disable(SerializationConfig.Feature.AUTO_DETECT_FIELDS);
objectMapper.getSerializationConfig().disable(AUTO_DETECT_GETTERS);
objectMapper.getSerializationConfig().disable(AUTO_DETECT_IS_GETTERS);
if (jsonSerializers != null || jsonDeserializers != null || keySerializers != null || keyDeserializers != null) {
SimpleModule module=new SimpleModule(getClass().getName(),new Version(1,0,0,null));
if (jsonSerializers != null) {
for ( Entry<Class<?>,JsonSerializer<?>> entry : jsonSerializers.entrySet()) {
addSerializer(module,entry.getKey(),entry.getValue());
}
}
if (jsonDeserializers != null) {
for ( Entry<Class<?>,JsonDeserializer<?>> entry : jsonDeserializers.entrySet()) {
addDeserializer(module,entry.getKey(),entry.getValue());
}
}
if (keySerializers != null) {
for ( Entry<Class<?>,JsonSerializer<?>> entry : keySerializers.entrySet()) {
addKeySerializer(module,entry.getKey(),entry.getValue());
}
}
if (keyDeserializers != null) {
for ( Entry<Class<?>,KeyDeserializer> entry : keyDeserializers.entrySet()) {
module.addKeyDeserializer(entry.getKey(),entry.getValue());
}
}
objectMapper.registerModule(module);
}
return objectMapper;
}

Example 17

From project RHQpocket, under directory /src/org/rhq/pocket/alert/.

Source file: AlertListFragment.java

  15 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
protected void fetchAlerts(){
String subUrl="/alert";
if (resourceId > 0) {
subUrl=subUrl + "?resourceId=" + resourceId;
}
new TalkToServerTask(getActivity(),new FinishCallback(){
@Override public void onSuccess( JsonNode result){
ObjectMapper objectMapper=new ObjectMapper();
objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES,false);
try {
alertList=objectMapper.readValue(result,new TypeReference<List<AlertRest>>(){
}
);
setListAdapter(new AlertListItemAdapter(getActivity(),R.layout.alert_list_item,alertList));
ProgressBar pb=(ProgressBar)layout.findViewById(R.id.list_progress);
if (pb != null) pb.setVisibility(View.GONE);
getListView().requestLayout();
getListView().requestLayout();
}
catch ( IOException e) {
e.printStackTrace();
}
}
@Override public void onFailure( Exception e){
e.printStackTrace();
}
}
,subUrl).execute();
}

Example 18

From project spring-social-facebook, under directory /spring-social-facebook-web/src/main/java/org/springframework/social/facebook/web/.

Source file: SignedRequestDecoder.java

  15 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
/**
* @param secret the application secret used in creating and verifying the signature of the signed request.
*/
public SignedRequestDecoder(String secret){
this.secret=secret;
this.objectMapper=new ObjectMapper();
this.objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES,false);
this.objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
}

Example 19

From project spring-social-flickr, under directory /core/src/main/java/org/springframework/social/flickr/api/impl/.

Source file: FlickrObjectMapper.java

  15 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
protected Object _unwrapAndDeserialize(JsonParser jp,JavaType rootType,DeserializationContext ctxt,JsonDeserializer<Object> deser) throws IOException, JsonParseException, JsonMappingException {
ObjectMapper mapper=new ObjectMapper();
mapper.setDeserializationConfig(ctxt.getConfig());
mapper.disable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
jp.setCodec(mapper);
JsonNode tree=jp.readValueAsTree();
JsonNode statNode=tree.get("stat");
String status=statNode.getTextValue();
if (!"ok".equals(status)) {
JsonNode msgNode=tree.get("message");
String errorMsg=msgNode.getTextValue();
JsonNode codeNode=tree.get("code");
String errorCode=codeNode.getTextValue();
throw new FlickrException(errorMsg);
}
jp=jp.getCodec().treeAsTokens(tree);
jp.nextToken();
SerializedString rootName=_deserializerProvider.findExpectedRootName(ctxt.getConfig(),rootType);
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw JsonMappingException.from(jp,"Current token not START_OBJECT (needed to unwrap root name '" + rootName + "'), but "+ jp.getCurrentToken());
}
if (jp.nextToken() != JsonToken.FIELD_NAME) {
throw JsonMappingException.from(jp,"Current token not FIELD_NAME (to contain expected root name '" + rootName + "'), but "+ jp.getCurrentToken());
}
String actualName=jp.getCurrentName();
if ("stat".equals(actualName)) {
return null;
}
jp.nextToken();
Object result=deser.deserialize(jp,ctxt);
jp.nextToken();
jp.nextToken();
if (jp.nextToken() != JsonToken.END_OBJECT) {
throw JsonMappingException.from(jp,"Current token not END_OBJECT (to match wrapper object with root name '" + rootName + "'), but "+ jp.getCurrentToken());
}
return result;
}

Example 20

From project st-js, under directory /server/src/main/java/org/stjs/server/json/jackson/.

Source file: JSArrayDeserializer.java

  15 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
/**
* Helper method called when current token is no START_ARRAY. Will either throw an exception, or try to handle value as if member of implicit array, depending on configuration.
*/
private final Array<Object> handleNonArray(JsonParser jp,DeserializationContext ctxt,Array<Object> result) throws IOException, JsonProcessingException {
if (!ctxt.isEnabled(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)) {
throw ctxt.mappingException(_collectionType.getRawClass());
}
JsonDeserializer<Object> valueDes=_valueDeserializer;
final TypeDeserializer typeDeser=_valueTypeDeserializer;
JsonToken t=jp.getCurrentToken();
Object value;
if (t == JsonToken.VALUE_NULL) {
value=null;
}
else if (typeDeser == null) {
value=valueDes.deserialize(jp,ctxt);
}
else {
value=valueDes.deserializeWithType(jp,ctxt,typeDeser);
}
result.push(value);
return result;
}

Example 21

From project wharf, under directory /wharf-core/src/main/java/org/jfrog/wharf/ivy/marshall/jackson/.

Source file: JacksonFactory.java

  15 
Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置
/**
* Update the parser with a default codec
* @param jsonFactory Factory to set as codec
* @param jsonParser Parser to configure
*/
private static void updateParser(JsonFactory jsonFactory,JsonParser jsonParser){
AnnotationIntrospector primary=new JacksonAnnotationIntrospector();
ObjectMapper mapper=new ObjectMapper(jsonFactory);
mapper.getSerializationConfig().setAnnotationIntrospector(primary);
mapper.getDeserializationConfig().setAnnotationIntrospector(primary);
mapper.getDeserializationConfig().disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
jsonParser.setCodec(mapper);
}