Java 类com.fasterxml.jackson.databind.AnnotationIntrospector 实例源码

项目:steve-plugsurfing    文件:WebSocketConfiguration.java   
@Bean
public ObjectMapper objectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    mapper.registerModule(new Ocpp12JacksonModule());
    mapper.registerModule(new Ocpp15JacksonModule());

    mapper.setAnnotationIntrospector(
            AnnotationIntrospector.pair(
                    new JacksonAnnotationIntrospector(),
                    new JaxbAnnotationIntrospector(mapper.getTypeFactory())
            )
    );
    return mapper;
}
项目:QuizUpWinner    文件:StdSubtypeResolver.java   
public Collection<NamedType> collectAndResolveSubtypes(AnnotatedClass paramAnnotatedClass, MapperConfig<?> paramMapperConfig, AnnotationIntrospector paramAnnotationIntrospector)
{
  HashMap localHashMap = new HashMap();
  if (this._registeredSubtypes != null)
  {
    Class localClass = paramAnnotatedClass.getRawType();
    Iterator localIterator = this._registeredSubtypes.iterator();
    while (localIterator.hasNext())
    {
      NamedType localNamedType = (NamedType)localIterator.next();
      if (localClass.isAssignableFrom(localNamedType.getType()))
        _collectAndResolve(AnnotatedClass.constructWithoutSuperTypes(localNamedType.getType(), paramAnnotationIntrospector, paramMapperConfig), localNamedType, paramMapperConfig, paramAnnotationIntrospector, localHashMap);
    }
  }
  _collectAndResolve(paramAnnotatedClass, new NamedType(paramAnnotatedClass.getRawType(), null), paramMapperConfig, paramAnnotationIntrospector, localHashMap);
  return new ArrayList(localHashMap.values());
}
项目:QuizUpWinner    文件:StdSerializer.java   
public JsonSerializer<?> findConvertingContentSerializer(SerializerProvider paramSerializerProvider, BeanProperty paramBeanProperty, JsonSerializer<?> paramJsonSerializer)
{
  AnnotationIntrospector localAnnotationIntrospector = paramSerializerProvider.getAnnotationIntrospector();
  if ((localAnnotationIntrospector != null) && (paramBeanProperty != null))
  {
    Object localObject = localAnnotationIntrospector.findSerializationContentConverter(paramBeanProperty.getMember());
    if (localObject != null)
    {
      Converter localConverter = paramSerializerProvider.converterInstance(paramBeanProperty.getMember(), localObject);
      JavaType localJavaType = localConverter.getOutputType(paramSerializerProvider.getTypeFactory());
      if (paramJsonSerializer == null)
        paramJsonSerializer = paramSerializerProvider.findValueSerializer(localJavaType, paramBeanProperty);
      return new StdDelegatingSerializer(localConverter, localJavaType, paramJsonSerializer);
    }
  }
  return paramJsonSerializer;
}
项目:QuizUpWinner    文件:BasicSerializerFactory.java   
public TypeSerializer createTypeSerializer(SerializationConfig paramSerializationConfig, JavaType paramJavaType)
{
  AnnotatedClass localAnnotatedClass = paramSerializationConfig.introspectClassAnnotations(paramJavaType.getRawClass()).getClassInfo();
  AnnotationIntrospector localAnnotationIntrospector = paramSerializationConfig.getAnnotationIntrospector();
  TypeResolverBuilder localTypeResolverBuilder = localAnnotationIntrospector.findTypeResolver(paramSerializationConfig, localAnnotatedClass, paramJavaType);
  Collection localCollection;
  if (localTypeResolverBuilder == null)
  {
    localTypeResolverBuilder = paramSerializationConfig.getDefaultTyper(paramJavaType);
    localCollection = null;
  }
  else
  {
    localCollection = paramSerializationConfig.getSubtypeResolver().collectAndResolveSubtypes(localAnnotatedClass, paramSerializationConfig, localAnnotationIntrospector);
  }
  if (localTypeResolverBuilder == null)
    return null;
  return localTypeResolverBuilder.buildTypeSerializer(paramSerializationConfig, paramJavaType, localCollection);
}
项目:QuizUpWinner    文件:BasicBeanDescription.java   
public Map<String, AnnotatedMember> findBackReferenceProperties()
{
  HashMap localHashMap = null;
  Iterator localIterator = this._properties.iterator();
  while (localIterator.hasNext())
  {
    AnnotatedMember localAnnotatedMember = ((BeanPropertyDefinition)localIterator.next()).getMutator();
    if (localAnnotatedMember != null)
    {
      AnnotationIntrospector.ReferenceProperty localReferenceProperty = this._annotationIntrospector.findReferenceType(localAnnotatedMember);
      if ((localReferenceProperty != null) && (localReferenceProperty.isBackReference()))
      {
        if (localHashMap == null)
          localHashMap = new HashMap();
        String str = localReferenceProperty.getName();
        if (localHashMap.put(str, localAnnotatedMember) != null)
          throw new IllegalArgumentException("Multiple back-reference properties with name '" + str + "'");
      }
    }
  }
  return localHashMap;
}
项目:QuizUpWinner    文件:POJOPropertiesCollector.java   
protected POJOPropertiesCollector(MapperConfig<?> paramMapperConfig, boolean paramBoolean, JavaType paramJavaType, AnnotatedClass paramAnnotatedClass, String paramString)
{
  this._config = paramMapperConfig;
  this._forSerialization = paramBoolean;
  this._type = paramJavaType;
  this._classDef = paramAnnotatedClass;
  String str;
  if (paramString == null)
    str = "set";
  else
    str = paramString;
  this._mutatorPrefix = str;
  AnnotationIntrospector localAnnotationIntrospector;
  if (paramMapperConfig.isAnnotationProcessingEnabled())
    localAnnotationIntrospector = this._config.getAnnotationIntrospector();
  else
    localAnnotationIntrospector = null;
  this._annotationIntrospector = localAnnotationIntrospector;
  if (this._annotationIntrospector == null)
  {
    this._visibilityChecker = this._config.getDefaultVisibilityChecker();
    return;
  }
  this._visibilityChecker = this._annotationIntrospector.findAutoDetectVisibility(paramAnnotatedClass, this._config.getDefaultVisibilityChecker());
}
项目:QuizUpWinner    文件:POJOPropertiesCollector.java   
protected void _addInjectables()
{
  AnnotationIntrospector localAnnotationIntrospector = this._annotationIntrospector;
  if (localAnnotationIntrospector == null)
    return;
  Iterator localIterator1 = this._classDef.fields().iterator();
  while (localIterator1.hasNext())
  {
    AnnotatedField localAnnotatedField = (AnnotatedField)localIterator1.next();
    _doAddInjectable(localAnnotationIntrospector.findInjectableValueId(localAnnotatedField), localAnnotatedField);
  }
  Iterator localIterator2 = this._classDef.memberMethods().iterator();
  while (localIterator2.hasNext())
  {
    AnnotatedMethod localAnnotatedMethod = (AnnotatedMethod)localIterator2.next();
    if (localAnnotatedMethod.getParameterCount() == 1)
      _doAddInjectable(localAnnotationIntrospector.findInjectableValueId(localAnnotatedMethod), localAnnotatedMethod);
  }
}
项目:QuizUpWinner    文件:POJOPropertiesCollector.java   
protected void _addMethods()
{
  AnnotationIntrospector localAnnotationIntrospector = this._annotationIntrospector;
  Iterator localIterator = this._classDef.memberMethods().iterator();
  while (localIterator.hasNext())
  {
    AnnotatedMethod localAnnotatedMethod = (AnnotatedMethod)localIterator.next();
    int i = localAnnotatedMethod.getParameterCount();
    if (i == 0)
    {
      _addGetterMethod(localAnnotatedMethod, localAnnotationIntrospector);
    }
    else if (i == 1)
    {
      _addSetterMethod(localAnnotatedMethod, localAnnotationIntrospector);
    }
    else if ((i == 2) && (localAnnotationIntrospector != null) && (localAnnotationIntrospector.hasAnySetterAnnotation(localAnnotatedMethod)))
    {
      if (this._anySetters == null)
        this._anySetters = new LinkedList();
      this._anySetters.add(localAnnotatedMethod);
    }
  }
}
项目:QuizUpWinner    文件:BasicClassIntrospector.java   
protected POJOPropertiesCollector collectPropertiesWithBuilder(MapperConfig<?> paramMapperConfig, JavaType paramJavaType, ClassIntrospector.MixInResolver paramMixInResolver, boolean paramBoolean)
{
  AnnotationIntrospector localAnnotationIntrospector;
  if (paramMapperConfig.isAnnotationProcessingEnabled())
    localAnnotationIntrospector = paramMapperConfig.getAnnotationIntrospector();
  else
    localAnnotationIntrospector = null;
  AnnotatedClass localAnnotatedClass = AnnotatedClass.construct(paramJavaType.getRawClass(), localAnnotationIntrospector, paramMixInResolver);
  JsonPOJOBuilder.Value localValue1;
  if (localAnnotationIntrospector == null)
    localValue1 = null;
  else
    localValue1 = localAnnotationIntrospector.findPOJOBuilderConfig(localAnnotatedClass);
  JsonPOJOBuilder.Value localValue2 = localValue1;
  String str;
  if (localValue1 == null)
    str = "with";
  else
    str = localValue2.withPrefix;
  return constructPropertyCollector(paramMapperConfig, localAnnotatedClass, paramJavaType, paramBoolean, str).collect();
}
项目:QuizUpWinner    文件:BasicDeserializerFactory.java   
public TypeDeserializer findTypeDeserializer(DeserializationConfig paramDeserializationConfig, JavaType paramJavaType)
{
  AnnotatedClass localAnnotatedClass = paramDeserializationConfig.introspectClassAnnotations(paramJavaType.getRawClass()).getClassInfo();
  AnnotationIntrospector localAnnotationIntrospector = paramDeserializationConfig.getAnnotationIntrospector();
  Object localObject = localAnnotationIntrospector.findTypeResolver(paramDeserializationConfig, localAnnotatedClass, paramJavaType);
  Collection localCollection;
  if (localObject == null)
  {
    TypeResolverBuilder localTypeResolverBuilder = paramDeserializationConfig.getDefaultTyper(paramJavaType);
    localObject = localTypeResolverBuilder;
    localCollection = null;
    if (localTypeResolverBuilder == null)
      return null;
  }
  else
  {
    localCollection = paramDeserializationConfig.getSubtypeResolver().collectAndResolveSubtypes(localAnnotatedClass, paramDeserializationConfig, localAnnotationIntrospector);
  }
  if ((((TypeResolverBuilder)localObject).getDefaultImpl() == null) && (paramJavaType.isAbstract()))
  {
    JavaType localJavaType = mapAbstractType(paramDeserializationConfig, paramJavaType);
    if ((localJavaType != null) && (localJavaType.getRawClass() != paramJavaType.getRawClass()))
      localObject = ((TypeResolverBuilder)localObject).defaultImpl(localJavaType.getRawClass());
  }
  return ((TypeResolverBuilder)localObject).buildTypeDeserializer(paramDeserializationConfig, paramJavaType, localCollection);
}
项目:QuizUpWinner    文件:StdDeserializer.java   
protected JsonDeserializer<?> findConvertingContentDeserializer(DeserializationContext paramDeserializationContext, BeanProperty paramBeanProperty, JsonDeserializer<?> paramJsonDeserializer)
{
  AnnotationIntrospector localAnnotationIntrospector = paramDeserializationContext.getAnnotationIntrospector();
  if ((localAnnotationIntrospector != null) && (paramBeanProperty != null))
  {
    Object localObject = localAnnotationIntrospector.findDeserializationContentConverter(paramBeanProperty.getMember());
    if (localObject != null)
    {
      Converter localConverter = paramDeserializationContext.converterInstance(paramBeanProperty.getMember(), localObject);
      JavaType localJavaType = localConverter.getInputType(paramDeserializationContext.getTypeFactory());
      if (paramJsonDeserializer == null)
        paramJsonDeserializer = paramDeserializationContext.findContextualValueDeserializer(localJavaType, paramBeanProperty);
      return new StdDelegatingDeserializer(localConverter, localJavaType, paramJsonDeserializer);
    }
  }
  return paramJsonDeserializer;
}
项目:QuizUpWinner    文件:BeanDeserializerFactory.java   
protected SettableBeanProperty constructSettableProperty(DeserializationContext paramDeserializationContext, BeanDescription paramBeanDescription, BeanPropertyDefinition paramBeanPropertyDefinition, Type paramType)
{
  AnnotatedMember localAnnotatedMember = paramBeanPropertyDefinition.getMutator();
  if (paramDeserializationContext.canOverrideAccessModifiers())
    localAnnotatedMember.fixAccess();
  JavaType localJavaType1 = paramBeanDescription.resolveType(paramType);
  BeanProperty.Std localStd = new BeanProperty.Std(paramBeanPropertyDefinition.getName(), localJavaType1, paramBeanPropertyDefinition.getWrapperName(), paramBeanDescription.getClassAnnotations(), localAnnotatedMember, paramBeanPropertyDefinition.isRequired());
  JavaType localJavaType2 = resolveType(paramDeserializationContext, paramBeanDescription, localJavaType1, localAnnotatedMember);
  if (localJavaType2 != localJavaType1)
    localStd.withType(localJavaType2);
  JsonDeserializer localJsonDeserializer = findDeserializerFromAnnotation(paramDeserializationContext, localAnnotatedMember);
  JavaType localJavaType3 = modifyTypeByAnnotation(paramDeserializationContext, localAnnotatedMember, localJavaType2);
  TypeDeserializer localTypeDeserializer = (TypeDeserializer)localJavaType3.getTypeHandler();
  Object localObject;
  if ((localAnnotatedMember instanceof AnnotatedMethod))
    localObject = new MethodProperty(paramBeanPropertyDefinition, localJavaType3, localTypeDeserializer, paramBeanDescription.getClassAnnotations(), (AnnotatedMethod)localAnnotatedMember);
  else
    localObject = new FieldProperty(paramBeanPropertyDefinition, localJavaType3, localTypeDeserializer, paramBeanDescription.getClassAnnotations(), (AnnotatedField)localAnnotatedMember);
  if (localJsonDeserializer != null)
    localObject = ((SettableBeanProperty)localObject).withValueDeserializer(localJsonDeserializer);
  AnnotationIntrospector.ReferenceProperty localReferenceProperty = paramBeanPropertyDefinition.findReferenceType();
  if ((localReferenceProperty != null) && (localReferenceProperty.isManagedReference()))
    ((SettableBeanProperty)localObject).setManagedReferenceName(localReferenceProperty.getName());
  return localObject;
}
项目:QuizUpWinner    文件:EnumValues.java   
public static EnumValues constructFromName(Class<Enum<?>> paramClass, AnnotationIntrospector paramAnnotationIntrospector)
{
  Enum[] arrayOfEnum = (Enum[])ClassUtil.findEnumType(paramClass).getEnumConstants();
  if (arrayOfEnum != null)
  {
    HashMap localHashMap = new HashMap();
    int i = arrayOfEnum.length;
    for (int j = 0; j < i; j++)
    {
      Enum localEnum = arrayOfEnum[j];
      localHashMap.put(localEnum, new SerializedString(paramAnnotationIntrospector.findEnumValue(localEnum)));
    }
    return new EnumValues(paramClass, localHashMap);
  }
  throw new IllegalArgumentException("Can not determine enum constants for Class " + paramClass.getName());
}
项目:QuizUpWinner    文件:EnumValues.java   
public static EnumValues constructFromToString(Class<Enum<?>> paramClass, AnnotationIntrospector paramAnnotationIntrospector)
{
  Enum[] arrayOfEnum = (Enum[])ClassUtil.findEnumType(paramClass).getEnumConstants();
  if (arrayOfEnum != null)
  {
    HashMap localHashMap = new HashMap();
    int i = arrayOfEnum.length;
    for (int j = 0; j < i; j++)
    {
      Enum localEnum = arrayOfEnum[j];
      localHashMap.put(localEnum, new SerializedString(localEnum.toString()));
    }
    return new EnumValues(paramClass, localHashMap);
  }
  throw new IllegalArgumentException("Can not determine enum constants for Class " + paramClass.getName());
}
项目:joyplus-tv    文件:StdSubtypeResolver.java   
@Override
public Collection<NamedType> collectAndResolveSubtypes(AnnotatedClass type,
        MapperConfig<?> config, AnnotationIntrospector ai)
{
    HashMap<NamedType, NamedType> subtypes = new HashMap<NamedType, NamedType>();
    // [JACKSON-257] then consider registered subtypes (which have precedence over annotations)
    if (_registeredSubtypes != null) {
        Class<?> rawBase = type.getRawType();
        for (NamedType subtype : _registeredSubtypes) {
            // is it a subtype of root type?
            if (rawBase.isAssignableFrom(subtype.getType())) { // yes
                AnnotatedClass curr = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), ai, config);
                _collectAndResolve(curr, subtype, config, ai, subtypes);
            }
        }
    }
    // and then check subtypes via annotations from base type (recursively)
    NamedType rootType = new NamedType(type.getRawType(), null);
    _collectAndResolve(type, rootType, config, ai, subtypes);
    return new ArrayList<NamedType>(subtypes.values());
}
项目:steve    文件:WebSocketConfiguration.java   
@Bean
public ObjectMapper objectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    mapper.registerModule(new Ocpp12JacksonModule());
    mapper.registerModule(new Ocpp15JacksonModule());

    mapper.setAnnotationIntrospector(
            AnnotationIntrospector.pair(
                    new JacksonAnnotationIntrospector(),
                    new JaxbAnnotationIntrospector(mapper.getTypeFactory())
            )
    );
    return mapper;
}
项目:mtgo-best-bot    文件:BotObjectMapper.java   
/**
 * Annotation introspector to use for serialization process
 * is configured separately for serialization and deserialization purposes
 */
public BotObjectMapper() {
    final AnnotationIntrospector introspector
            = new JacksonAnnotationIntrospector();
    super.getDeserializationConfig()
            .with(introspector);
    super.getSerializationConfig()
            .with(introspector);

}
项目:mpd-tools    文件:MPDParser.java   
public static ObjectMapper defaultObjectMapper() {
    return new XmlMapper(new XmlFactory(new WstxInputFactory(), new WstxPrefixedOutputFactory()))
            .enable(SerializationFeature.INDENT_OUTPUT)
            .setSerializationInclusion(JsonInclude.Include.NON_NULL)
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true)
            .configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE, true)
            .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
            .registerModule(new ParserModule())
            .setAnnotationIntrospector(AnnotationIntrospector.pair(
                    new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()),
                    new JacksonAnnotationIntrospector()));
}
项目:crnk-framework    文件:AnnotatedClassBuilder.java   
private static AnnotatedClass buildOldAnnotatedClass(Method method, Class<?> declaringClass,
        SerializationConfig serializationConfig)
        throws InvocationTargetException, IllegalAccessException {
    boolean useAnnotations = serializationConfig.isAnnotationProcessingEnabled();
    AnnotationIntrospector aintr = useAnnotations ? serializationConfig.getAnnotationIntrospector() : null;
    return AnnotatedClass.class.cast(method.invoke(null, declaringClass, aintr, serializationConfig));
}
项目:jee-demo    文件:PersonDTOTest.java   
@Test
public void testSerializeJSON() throws IOException {

    Person person = new Person();
    person.setId(12345L);
    person.setFirstName("Peter");
    person.setLastName("Walser");
    person.setGender(Gender.MALE);
    person.setDateOfBirth(LocalDate.of(1975, 12, 20));

    StringWriter buffer = new StringWriter();
    ObjectMapper mapper = new ObjectMapper();

    mapper.setAnnotationIntrospector(
            AnnotationIntrospector.pair(
                    new JacksonAnnotationIntrospector(),
                    new JaxbAnnotationIntrospector(mapper.getTypeFactory())
            )
    );
    mapper.writerWithDefaultPrettyPrinter().writeValue(buffer, person);

    String jsonString = buffer.toString();
    System.out.println(jsonString);

    Assert.assertTrue(jsonString.contains("\"id\" : 12345"));
    Assert.assertTrue(jsonString.contains("\"first_name\" : \"Peter\""));
    Assert.assertTrue(jsonString.contains("\"last_name\" : \"Walser\""));
    Assert.assertTrue(jsonString.contains("\"gender\" : \"MALE\""));
    Assert.assertTrue(jsonString.contains("\"birth_date\" : \"1975-12-20\""));

}
项目:SNOMED-in-5-minutes    文件:Utility.java   
/**
 * Returns the graph for json.
 *
 * @param <T> the generic type
 * @param json the json
 * @param graphClass the graph class
 * @return the graph for json
 * @throws Exception the exception
 */
public static <T> T getGraphForJson(String json, Class<T> graphClass)
  throws Exception {
  InputStream in =
      new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8));
  ObjectMapper mapper = new ObjectMapper();
  AnnotationIntrospector introspector =
      new JaxbAnnotationIntrospector(mapper.getTypeFactory());
  mapper.setAnnotationIntrospector(introspector);
  return mapper.readValue(in, graphClass);

}
项目:SNOMED-in-5-minutes    文件:Utility.java   
/**
 * Returns the json for graph.
 *
 * @param object the object
 * @return the json for graph
 * @throws Exception the exception
 */
public static String getJsonForGraph(Object object) throws Exception {
  ObjectMapper mapper = new ObjectMapper();
  AnnotationIntrospector introspector =
      new JaxbAnnotationIntrospector(mapper.getTypeFactory());
  mapper.setAnnotationIntrospector(introspector);
  return mapper.writeValueAsString(object);
}
项目:jacksonatic    文件:JacksonaticClassIntrospector.java   
@Override
public BasicBeanDescription forDirectClassAnnotations(MapperConfig<?> cfg, JavaType type, MixInResolver r) {
    BasicBeanDescription desc = _findStdTypeDesc(type);
    if (desc == null) {
        boolean useAnnotations = cfg.isAnnotationProcessingEnabled();
        AnnotationIntrospector ai = cfg.getAnnotationIntrospector();
        AnnotatedClass ac = annotatedClassConstructor.constructWithoutSuperTypes(type.getRawClass(),
                (useAnnotations ? ai : null), r);
        desc = BasicBeanDescription.forOtherUse(cfg, type, ac);
    }
    return desc;
}
项目:jacksonatic    文件:JacksonaticClassIntrospector.java   
protected POJOPropertiesCollector collectPropertiesWithBuilder(MapperConfig<?> config, JavaType type, MixInResolver r, boolean forSerialization) {
    boolean useAnnotations = config.isAnnotationProcessingEnabled();
    AnnotationIntrospector ai = useAnnotations ? config.getAnnotationIntrospector() : null;
    AnnotatedClass ac;
    if (forSerialization) {
        ac = annotatedClassConstructor.constructForSerialization(type.getRawClass(), ai, r);
    } else {
        ac = annotatedClassConstructor.constructForDeserialization(type.getRawClass(), ai, r);
    }
    JsonPOJOBuilder.Value builderConfig = (ai == null) ? null : ai.findPOJOBuilderConfig(ac);
    String mutatorPrefix = (builderConfig == null) ? "with" : builderConfig.withPrefix;
    return constructPropertyCollector(config, ac, type, forSerialization, mutatorPrefix).collect();
}
项目:katharsis-framework    文件:AnnotatedClassBuilder.java   
private static AnnotatedClass buildOldAnnotatedClass(Method method, Class<?> declaringClass,
                                                     SerializationConfig serializationConfig)
    throws InvocationTargetException, IllegalAccessException {
    boolean useAnnotations = serializationConfig.isAnnotationProcessingEnabled();
    AnnotationIntrospector aintr = useAnnotations ? serializationConfig.getAnnotationIntrospector() : null;
    return AnnotatedClass.class.cast(method.invoke(null, declaringClass, aintr, serializationConfig));
}
项目:endpoints-java    文件:ObjectMapperUtil.java   
/**
 * Creates an Endpoints standard object mapper that allows unquoted field names and unknown
 * properties.
 *
 * Note on unknown properties: When Apiary FE supports a strict mode where properties
 * are checked against the schema, BE can just ignore unknown properties.  This way, FE does
 * not need to filter out everything that the BE doesn't understand.  Before that's done,
 * a property name with a typo in it, for example, will just be ignored by the BE.
 */
public static ObjectMapper createStandardObjectMapper(ApiSerializationConfig config) {
  ObjectMapper objectMapper = new ObjectMapper()
      .configure(JsonParser.Feature.ALLOW_COMMENTS, true)
      .configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true)
      .configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
      .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
      .setBase64Variant(Base64Variants.MODIFIED_FOR_URL)
      .setSerializerFactory(
          BeanSerializerFactory.instance.withSerializerModifier(new DeepEmptyCheckingModifier()));
  AnnotationIntrospector pair = AnnotationIntrospector.pair(
      new ApiAnnotationIntrospector(config), new JacksonAnnotationIntrospector());
  objectMapper.setAnnotationIntrospector(pair);
  return objectMapper;
}
项目:OSHv4    文件:BcontrolSmartMeterDriver.java   
public void receiveHeaterMessageFromMeter(String msg) throws Exception {
        // parse to JSON and send to database

        // Setting up Jackson Tree Model with ObjectMapper
        ObjectMapper om = new ObjectMapper();
        AnnotationIntrospector introspectorJackson = new JacksonAnnotationIntrospector();

        om.setAnnotationIntrospector(introspectorJackson);

        // Retrieve JSON responses from controller and build Jackson Tree
        // Model with package de.fzi.iik.habiteq.jackson
        BcontrolHeaterData bchd = null;
//      try {
            bchd = om.readValue(msg, BcontrolHeaterData.class);
//      } 
//      catch (JsonParseException e) {
//          getGlobalLogger().logWarning(e.getStackTrace(), e);
//      } 
//      catch (JsonMappingException e) {
//          getGlobalLogger().logWarning(e.getStackTrace(), e);
//      } 
//      catch (IOException e) {
//          getGlobalLogger().logWarning(e.getStackTrace(), e);
//      }

//      getGlobalLogger().logDebug(msg);
//      getGlobalLogger().logDebug(bcmd);

        // save to registry
        getDriverRegistry().setStateOfSender(
                BcontrolHeaterDriverRawLogDetails.class, 
                convertJsonToRawDetails(bchd));
    }
项目:Robusto    文件:SpringClientConfiguration.java   
/**
 * Build a default Jackson ObjectMapper. The default implementation is to
 * include non-null, ignore uknown properties on deserialization, and use
 * the date format yyyy-MM-dd'T'HH:mm:ssZ.
 * @return A Jackson ObjectMapper.
 */
protected ObjectMapper buildDefaultJacksonObjectMapper()
{
   /* Cant use unless Spring 4.x is being used throughout
   return new Jackson2ObjectMapperBuilder()
         .serializationInclusion(JsonInclude.Include.NON_NULL)
         .failOnUnknownProperties(false)
         .dateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"))
         .featuresToEnable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME)
         .annotationIntrospector(AnnotationIntrospector.pair(
               new JacksonAnnotationIntrospector(),
               new JaxbAnnotationIntrospector()))
         .build();
         */
   ObjectMapper mapper = new ObjectMapper();
   mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
   mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
   mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"));
   mapper.enable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME);
   mapper.registerModule(new JodaModule());

   AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
   AnnotationIntrospector secondary = new JaxbAnnotationIntrospector();
   mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(primary, secondary));

   return mapper;
}
项目:keystone4j    文件:JacksonProvider.java   
public JacksonProvider() {
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
    // if using BOTH JAXB annotations AND Jackson annotations:
    AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();

    ObjectMapper mapper = new ObjectMapper().registerModule(new Hibernate4Module())
            .setSerializationInclusion(Include.NON_NULL)
            .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false).enable(SerializationFeature.INDENT_OUTPUT)
            .setAnnotationIntrospector(new AnnotationIntrospectorPair(introspector, secondary));
    // mapper = mapper.setSerializationInclusion(Include)
    setMapper(mapper);
}
项目:keystone4j    文件:ObjectMapperResolver.java   
public ObjectMapperResolver() {
    objectMapper = new ObjectMapper();
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
    AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
    objectMapper = objectMapper.setAnnotationIntrospector(new AnnotationIntrospectorPair(introspector, secondary));
    objectMapper = objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    objectMapper.registerModule(new Hibernate4Module());
}
项目:UMLS-Terminology-Server    文件:ConfigUtility.java   
/**
 * Returns the graph for json.
 *
 * @param <T> the generic type
 * @param json the json
 * @param graphClass the graph class
 * @return the graph for json
 * @throws Exception the exception
 */
public static <T> T getGraphForJson(String json, Class<T> graphClass)
  throws Exception {
  if (ConfigUtility.isEmpty(json)) {
    return null;
  }
  InputStream in =
      new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8));
  ObjectMapper mapper = new ObjectMapper();
  AnnotationIntrospector introspector =
      new JaxbAnnotationIntrospector(mapper.getTypeFactory());
  mapper.setAnnotationIntrospector(introspector);
  return mapper.readValue(in, graphClass);

}
项目:UMLS-Terminology-Server    文件:ConfigUtility.java   
/**
 * Returns the graph for json. sample usage:
 * 
 * <pre>
 *   List&lt;ConceptJpa&gt; list = ConfigUtility.getGraphForJson(str, new TypeReference&lt;List&lt;ConceptJpa&gt;&gt;{});
 * </pre>
 * 
 * @param <T> the
 * @param json the json
 * @param typeRef the type ref
 * @return the graph for json
 * @throws Exception the exception
 */
public static <T> T getGraphForJson(String json, TypeReference<T> typeRef)
  throws Exception {
  if (ConfigUtility.isEmpty(json)) {
    return null;
  }
  InputStream in =
      new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8));
  ObjectMapper mapper = new ObjectMapper();
  AnnotationIntrospector introspector =
      new JaxbAnnotationIntrospector(mapper.getTypeFactory());
  mapper.setAnnotationIntrospector(introspector);
  return mapper.readValue(in, typeRef);

}
项目:UMLS-Terminology-Server    文件:ConfigUtility.java   
/**
 * Returns the json for graph.
 *
 * @param object the object
 * @return the json for graph
 * @throws Exception the exception
 */
public static String getJsonForGraph(Object object) throws Exception {
  ObjectMapper mapper = new ObjectMapper();
  AnnotationIntrospector introspector =
      new JaxbAnnotationIntrospector(mapper.getTypeFactory());
  mapper.setAnnotationIntrospector(introspector);
  return mapper.writeValueAsString(object);
}
项目:UMLS-Terminology-Server    文件:ObjectMapperProvider.java   
/**
 * Creates the combined object mapper.
 *
 * @return the object mapper
 */
private static ObjectMapper createDefaultMapper() {
  ObjectMapper mapper = new ObjectMapper();
  AnnotationIntrospector introspector =
      new JaxbAnnotationIntrospector(mapper.getTypeFactory());
  mapper.setAnnotationIntrospector(introspector);

  // final AnnotationIntrospector jacksonIntrospector =
  // new JacksonAnnotationIntrospector();
  // return AnnotationIntrospector.pair(jacksonIntrospector,
  // jaxbIntrospector);
  return mapper;
}
项目:eMonocot    文件:HibernateModule.java   
@Override
public void setupModule(SetupContext context)
{
    /* First, append annotation introspector (no need to override, esp.
     * as we just implement couple of methods)
     */
    // Then add serializers we need
    AnnotationIntrospector ai = annotationIntrospector();
    if (ai != null) {
        context.appendAnnotationIntrospector(ai);
    }
    context.addSerializers(new HibernateSerializers(_moduleFeatures));
}
项目:PDFReporter-Studio    文件:JacksonHelper.java   
public static ObjectMapper getJSONMapper() {
    ObjectMapper mapper = new ObjectMapper();
    AnnotationIntrospector primary = new JaxbAnnotationIntrospector(mapper.getTypeFactory());
    AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
    mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(primary, secondary));
    setupMapper(mapper);
    return mapper;
}
项目:PDFReporter-Studio    文件:JacksonHelper.java   
public static XmlMapper getXMLMapper() {
    XmlMapper mapper = new XmlMapper();
    AnnotationIntrospector primary = new XmlJaxbAnnotationIntrospector(mapper.getTypeFactory());
    AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
    mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(primary, secondary));
    setupMapper(mapper);
    return mapper;
}
项目:Robusto    文件:SpringClientConfiguration.java   
/**
 * Build a default Jackson ObjectMapper. The default implementation is to
 * include non-null, ignore uknown properties on deserialization, and use
 * the date format yyyy-MM-dd'T'HH:mm:ssZ.
 * @return A Jackson ObjectMapper.
 */
protected ObjectMapper buildDefaultJacksonObjectMapper()
{
   /* Cant use unless Spring 4.x is being used throughout
   return new Jackson2ObjectMapperBuilder()
         .serializationInclusion(JsonInclude.Include.NON_NULL)
         .failOnUnknownProperties(false)
         .dateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"))
         .featuresToEnable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME)
         .annotationIntrospector(AnnotationIntrospector.pair(
               new JacksonAnnotationIntrospector(),
               new JaxbAnnotationIntrospector()))
         .build();
         */
   ObjectMapper mapper = new ObjectMapper();
   mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
   mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
   mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"));
   mapper.enable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME);
   mapper.registerModule(new JodaModule());

   AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
   AnnotationIntrospector secondary = new JaxbAnnotationIntrospector();
   mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(primary, secondary));

   return mapper;
}
项目:components    文件:ApiObjectMapper.java   
public ApiObjectMapper() {
    // Print the JSON with indentation (ie. pretty print)
    configure(SerializationFeature.INDENT_OUTPUT, true);

    // Allow JAX-B annotations.
    setAnnotationIntrospector(AnnotationIntrospector.pair(getSerializationConfig().getAnnotationIntrospector(),
            new JaxbAnnotationIntrospector()));

    // Make Jackson respect @XmlElementWrapper.
    enable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME);

    // Print all dates in ISO8601 format
    setDateFormat(makeISODateFormat());
}
项目:oap    文件:Binder.java   
private static ObjectMapper initialize( ObjectMapper mapper, boolean defaultTyping, boolean nonNullInclusion ) {
    if( mapper instanceof XmlMapper ) {
        ( ( XmlMapper ) mapper ).setDefaultUseWrapper( false );
    }
    AnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
    mapper.getDeserializationConfig().with( introspector );
    mapper.getSerializationConfig().with( introspector );
    mapper.registerModule( new AfterburnerModule() );
    mapper.registerModule( new Jdk8Module().configureAbsentsAsNulls( true ) );
    mapper.registerModule( new JodaModule() );
    mapper.registerModule( new ParameterNamesModule( JsonCreator.Mode.DEFAULT ) );
    mapper.enable( DeserializationFeature.USE_LONG_FOR_INTS );
    mapper.enable( JsonParser.Feature.ALLOW_SINGLE_QUOTES );
    mapper.disable( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES );
    mapper.disable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS );
    mapper.disable( SerializationFeature.WRITE_EMPTY_JSON_ARRAYS );
    mapper.disable( SerializationFeature.FAIL_ON_EMPTY_BEANS );
    mapper.configure( JsonGenerator.Feature.AUTO_CLOSE_TARGET, false );
    mapper.setVisibility( PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY );
    if( !nonNullInclusion ) mapper.setSerializationInclusion( JsonInclude.Include.NON_NULL );

    modules.forEach( mapper::registerModule );

    if( defaultTyping )
        mapper.enableDefaultTyping( ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY );

    return mapper;
}