當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。