当前位置: 首页>>代码示例>>Java>>正文


Java JsonDeserializer类代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.JsonDeserializer的典型用法代码示例。如果您正苦于以下问题:Java JsonDeserializer类的具体用法?Java JsonDeserializer怎么用?Java JsonDeserializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JsonDeserializer类属于com.fasterxml.jackson.databind包,在下文中一共展示了JsonDeserializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initClient

import com.fasterxml.jackson.databind.JsonDeserializer; //导入依赖的package包/类
private static void initClient() {
  JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
  ObjectMapper objectMapper = JSONUtil.prettyMapper();
  objectMapper.registerModule(
    new SimpleModule()
      .addDeserializer(JobDataFragment.class,
        new JsonDeserializer<JobDataFragment>() {
          @Override
          public JobDataFragment deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
            return jsonParser.readValueAs(DataPOJO.class);
          }
        }
      )
  );
  provider.setMapper(objectMapper);
  client = ClientBuilder.newBuilder().register(provider).register(MultiPartFeature.class).build();
  WebTarget rootTarget = client.target("http://localhost:" + currentDremioDaemon.getWebServer().getPort());
  currentApiV2 = rootTarget.path(API_LOCATION);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:20,代码来源:TestMasterDown.java

示例2: createDeserializationProblemHandler

import com.fasterxml.jackson.databind.JsonDeserializer; //导入依赖的package包/类
/**
 * Create a DeserializationProblemHandler that may be added to an
 * ObjectMapper, and will handle unknown properties by forwarding 
 * the error information to the given consumer, if it is not 
 * <code>null</code>
 * 
 * @param jsonErrorConsumer The consumer for {@link JsonError}s
 * @return The problem handler
 */
private static DeserializationProblemHandler 
    createDeserializationProblemHandler(
        Consumer<? super JsonError> jsonErrorConsumer)
{
    return new DeserializationProblemHandler()
    {
        @Override
        public boolean handleUnknownProperty(
            DeserializationContext ctxt, JsonParser jp, 
            JsonDeserializer<?> deserializer, Object beanOrClass, 
            String propertyName) 
                throws IOException, JsonProcessingException
        {
            if (jsonErrorConsumer != null)
            {
                jsonErrorConsumer.accept(new JsonError(
                    "Unknown property: " + propertyName, 
                    jp.getParsingContext(), null));
            }
            return super.handleUnknownProperty(
                ctxt, jp, deserializer, beanOrClass, propertyName);
        }
    };
}
 
开发者ID:javagl,项目名称:JglTF,代码行数:34,代码来源:JacksonUtils.java

示例3: testDeserialize

import com.fasterxml.jackson.databind.JsonDeserializer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testDeserialize() {
  boolean status = false;
  try {
    DeserializationContext ctxt = Mockito.mock(DeserializationContext.class);
    @SuppressWarnings("rawtypes")
    JsonDeserializer JsonDeserializer = Mockito.mock(JsonDeserializer.class);
    Object object = null;
    Mockito.when(jsonParser.nextFieldName()).thenReturn("abc", (String) null);
    Mockito.when(readerHelpData.getDeser()).thenReturn(JsonDeserializer);
    Mockito.when(JsonDeserializer.deserialize(jsonParser, ctxt)).thenReturn(object);
    Object deserializeObject = abstractDeserializer.deserialize(jsonParser, ctxt);
    Assert.assertNotNull(deserializeObject);
  } catch (Exception e) {
    status = true;
  }
  Assert.assertFalse(status);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:20,代码来源:TestAbstractDeserializer.java

示例4: newWrappingModule

import com.fasterxml.jackson.databind.JsonDeserializer; //导入依赖的package包/类
private static <T1, T2> SimpleModule newWrappingModule(final Class<T1> wrapped, final Class<T2> wrapper, final Converter<T1, T2> converter) {
  SimpleModule module = new SimpleModule();
  module.addDeserializer(wrapper, new JsonDeserializer<T2>() {
    @Override
    public T2 deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
      return converter.convert(ctxt.readValue(p, wrapped));
    }
  });
  module.addSerializer(wrapper, new JsonSerializer<T2>() {
    @Override
    public void serialize(T2 value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
      serializers.defaultSerializeValue(converter.revert(value), gen);
    }
  });
  return module;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:17,代码来源:JSONUtil.java

示例5: initMasterClient

import com.fasterxml.jackson.databind.JsonDeserializer; //导入依赖的package包/类
private static void initMasterClient() {
  JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
  ObjectMapper objectMapper = JSONUtil.prettyMapper();
  objectMapper.registerModule(
    new SimpleModule()
      .addDeserializer(JobDataFragment.class,
        new JsonDeserializer<JobDataFragment>() {
          @Override
          public JobDataFragment deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
            return jsonParser.readValueAs(DataPOJO.class);
          }
        }
      )
  );
  provider.setMapper(objectMapper);
  masterClient = ClientBuilder.newBuilder().register(provider).register(MultiPartFeature.class).build();
  WebTarget rootTarget = masterClient.target("http://localhost:" + masterDremioDaemon.getWebServer().getPort());
  masterApiV2 = rootTarget.path(API_LOCATION);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:20,代码来源:TestMasterDown.java

示例6: setupModule

import com.fasterxml.jackson.databind.JsonDeserializer; //导入依赖的package包/类
@Override
public void setupModule(final SetupContext context) {
    super.setupModule(context);
    context.addBeanDeserializerModifier(new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<?> modifyCollectionDeserializer(final DeserializationConfig config,
                                                                final CollectionType type,
                                                                final BeanDescription beanDesc,
                                                                final JsonDeserializer<?> deserializer) {
            if (deserializer instanceof CollectionDeserializer) {
                return new ListDeserializer((CollectionDeserializer) deserializer);
            } else {
                return super.modifyCollectionDeserializer(config, type, beanDesc,
                        deserializer);
            }
        }
    });
}
 
开发者ID:allure-framework,项目名称:allure2,代码行数:19,代码来源:XmlParserModule.java

示例7: modifyMapDeserializer

import com.fasterxml.jackson.databind.JsonDeserializer; //导入依赖的package包/类
@Override
public JsonDeserializer<?> modifyMapDeserializer(
		DeserializationConfig config, MapType type,
		BeanDescription beanDesc,
		JsonDeserializer<?> deserializer) {
	
	// statements
	if (isMapOfStringAndListOfStatements(type)) {
		return new ModifiedMapDeserializer<String, List<JacksonStatement>>(deserializer);
	}
	// labels and descriptions
	else if (isMapOfStringAndMonolingualTextValue(type)) {
		return new ModifiedMapDeserializer<String, JacksonMonolingualTextValue>(deserializer);
	}
	// sitelinks
	else if (isMapOfStringAndSitelink(type)) {
		return new ModifiedMapDeserializer<String, JacksonSiteLink>(deserializer);
	}
	// aliases and miscallaneous that does not need this workaround
	else {
		return deserializer;
	}
}
 
开发者ID:heindorf,项目名称:cikm16-wdvd-feature-extraction,代码行数:24,代码来源:MapDeserializerModifier.java

示例8: objectMapper

import com.fasterxml.jackson.databind.JsonDeserializer; //导入依赖的package包/类
@Bean
public ObjectMapper objectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    SimpleModule module = new SimpleModule();
    module.setDeserializerModifier( new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<Enum> modifyEnumDeserializer( DeserializationConfig config, final JavaType type, BeanDescription beanDesc,
          final JsonDeserializer<?> deserializer ) {
            return new JsonDeserializer<Enum>() {
                @Override
                public Enum deserialize( JsonParser jp, DeserializationContext ctxt ) throws IOException {
                    Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass();
                    return Enum.valueOf( rawClass, jp.getValueAsString().toUpperCase() );
                }
            };
        }
    } );

    module.addDeserializer( Expression.class, new ExpressionDeserializer( expressionParser() ) );
    module.addDeserializer( Range.class, new RangeDeserializer() );
    mapper.registerModule( module );

    return mapper;
}
 
开发者ID:cslee00,项目名称:datadog-jmx-collector,代码行数:25,代码来源:JmxCollectorMain.java

示例9: addJsonBean

import com.fasterxml.jackson.databind.JsonDeserializer; //导入依赖的package包/类
private void addJsonBean(Object bean) {
	if (bean instanceof JsonSerializer) {
		addSerializerWithDeducedType((JsonSerializer<?>) bean);
	}
	if (bean instanceof JsonDeserializer) {
		addDeserializerWithDeducedType((JsonDeserializer<?>) bean);
	}
	for (Class<?> innerClass : bean.getClass().getDeclaredClasses()) {
		if (JsonSerializer.class.isAssignableFrom(innerClass)
				|| JsonDeserializer.class.isAssignableFrom(innerClass)) {
			try {
				addJsonBean(innerClass.newInstance());
			}
			catch (Exception ex) {
				throw new IllegalStateException(ex);
			}
		}
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:JsonComponentModule.java

示例10: getJsonDeserializer

import com.fasterxml.jackson.databind.JsonDeserializer; //导入依赖的package包/类
private static <TFrom, TTo> JsonDeserializer<TFrom> getJsonDeserializer(
    @Nullable final Transformer<TFrom, TTo> serializer) {
  if (serializer == null) {
    return null;
  }
  final TypeReference<TTo> serializedType = typeReferenceOf(serializer);
  if (serializer instanceof ResourceTransformer) {
    @SuppressWarnings("unchecked")
    final ResourceTransformer<TFrom> resourceSerializer = (ResourceTransformer<TFrom>) serializer;
    return new ResourceDeserializer<>(resourceSerializer);
  } else {
    return new JsonDeserializer<TFrom>() {
      @Override
      public TFrom deserialize(JsonParser jp, DeserializationContext ctxt)
          throws IOException {
        TTo deserialized = jp.readValueAs(serializedType);
        return serializer.transformFrom(deserialized);
      }
    };
  }
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:22,代码来源:ApiAnnotationIntrospector.java

示例11: newInstance

import com.fasterxml.jackson.databind.JsonDeserializer; //导入依赖的package包/类
public static ObjectMapper newInstance() {
	ObjectMapper mapper = new ObjectMapper();
	//mapper.setSerializationInclusion(Inclusion.ALWAYS);
	//mapper.configure(SerializationConfig.Feature.WRITE_NULL_MAP_VALUES, false);
	//mapper.getSerializerProvider().setNullValueSerializer(new NullValueSerializer());
	
	/*Json反序列化时忽略多余的属性*/
	mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	
	SimpleModule module = new SimpleModule("JsonUtil", new Version(1, 0, 0, null));
	//JavaObject to JSONString
	module.addSerializer(new ToJsonLongSerializer());
	module.addSerializer(new ToJsonSqlTimestampSerializer(DEFAULT_DATETIME_PATTERN));
	module.addSerializer(new ToJsonDateSerializer(DEFAULT_DATETIME_PATTERN));
	module.addSerializer(new ToJsonStringSerializer());
	//JSONString to JavaObject
	module.addDeserializer(Date.class, new CustomDateDeSerializer(Date.class,DEFAULT_FORMATS));
	module.addDeserializer(Timestamp.class, (JsonDeserializer)new CustomSqlTimestampDeSerializer(Timestamp.class,DEFAULT_FORMATS));
	module.addDeserializer(java.sql.Date.class,(JsonDeserializer)new CustomSqlDateDeSerializer(java.sql.Date.class, DEFAULT_FORMATS));
	
	mapper.registerModule(module);
	return mapper;
}
 
开发者ID:thinking-github,项目名称:nbone,代码行数:24,代码来源:JsonUtils.java

示例12: anInlineAssociationDeserializerMatching

import com.fasterxml.jackson.databind.JsonDeserializer; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private static Matcher<JsonDeserializer> anInlineAssociationDeserializerMatching(
		final Matcher<RestOperations> restOperations, final ClientProxyFactory proxyFactory) {
	return new TypeSafeMatcher<JsonDeserializer>() {

		@Override
		public boolean matchesSafely(JsonDeserializer item) {
			if (!(item instanceof InlineAssociationDeserializer)) {
				return false;
			}
			
			InlineAssociationDeserializer other = (InlineAssociationDeserializer) item;
			
			return restOperations.matches(other.getRestOperations())
					&& proxyFactory == other.getProxyFactory();
		}

		@Override
		public void describeTo(Description description) {
			description.appendText("instanceof ").appendValue(InlineAssociationDeserializer.class)
				.appendText(", restOperations ").appendValue(restOperations)
				.appendText(", proxyFactory ").appendValue(proxyFactory);
		}
	};
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:26,代码来源:RestOperationsFactoryTest.java

示例13: createContextual

import com.fasterxml.jackson.databind.JsonDeserializer; //导入依赖的package包/类
@Override
 public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
         BeanProperty property) throws JsonMappingException
 {
     JsonFormat.Value format = findFormatOverrides(ctxt, property, handledType());
     if (format != null) {
         if (format.hasPattern()) {
             final String pattern = format.getPattern();
             final Locale locale = format.hasLocale() ? format.getLocale() : ctxt.getLocale();
             DateTimeFormatter df;
             if (locale == null) {
                 df = DateTimeFormatter.ofPattern(pattern);
             } else {
                 df = DateTimeFormatter.ofPattern(pattern, locale);
             }
             //Issue #69: For instant serializers/deserializers we need to configure the formatter with
             //a time zone picked up from JsonFormat annotation, otherwise serialization might not work
             if (format.hasTimeZone()) {
                 df = df.withZone(format.getTimeZone().toZoneId());
             }
             return withDateFormat(df);
         }
         // any use for TimeZone?
     }
     return this;
}
 
开发者ID:FasterXML,项目名称:jackson-modules-java8,代码行数:27,代码来源:JSR310DateTimeDeserializerBase.java

示例14: deserialize

import com.fasterxml.jackson.databind.JsonDeserializer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Analyzer<?> deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException, JsonProcessingException {
	final JsonDeserializer<?> specDeserializer = ctxt
			.findNonContextualValueDeserializer(TypeFactory.defaultInstance().uncheckedSimpleType(AnalyzerSpec.class));

	final AnalyzerSpec spec = (AnalyzerSpec) specDeserializer.deserialize(p, ctxt);

	final AnalyzerCreationResult creationResult = spec.getAnalyzerType().tryCreateAnalyzer(spec);
	if (!creationResult.wasSuccessful()) {
		throw new IOException(
				"Could not create analyzer from spec, global result: " + creationResult.getGlobalResult() + ", parameter results: ");
	}

	return creationResult.getAnalyzer();
}
 
开发者ID:mizitch,项目名称:story-inspector,代码行数:17,代码来源:JsonMappingSpringConfig.java

示例15: JsonObjectMapper

import com.fasterxml.jackson.databind.JsonDeserializer; //导入依赖的package包/类
/**
 * Constructor
 * Adds the provided list of custom serializers to the object mapper returned by this class.
 * @param jsonObjectSerializers list of custom serializers to be used by the object mapper
 */
@Autowired
public JsonObjectMapper(JsonObjectSerializers jsonObjectSerializers) {
    SimpleModule entityModule = new SimpleModule("de.oliverwetterau.neo4j.websockets");

    entityModule.addSerializer(Result.class, new ResultSerializer());
    entityModule.addSerializer(de.oliverwetterau.neo4j.websockets.core.data.Error.class, new ErrorSerializer());

    entityModule.addDeserializer(Result.class, new ResultDeserializer());

    if (jsonObjectSerializers != null) {
        for (Map.Entry<Class,JsonSerializer> jsonSerializer : jsonObjectSerializers.getSerializers().entrySet()) {
            entityModule.addSerializer(jsonSerializer.getKey(), jsonSerializer.getValue());
        }

        for (Map.Entry<Class,JsonDeserializer> jsonDeserializer : jsonObjectSerializers.getDeserializers().entrySet()) {
            entityModule.addDeserializer(jsonDeserializer.getKey(), jsonDeserializer.getValue());
        }
    }

    textObjectMapper.registerModule(entityModule);
    binaryObjectMapper.registerModule(entityModule);
}
 
开发者ID:owetterau,项目名称:neo4j-websockets,代码行数:28,代码来源:JsonObjectMapper.java


注:本文中的com.fasterxml.jackson.databind.JsonDeserializer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。