Java 类com.fasterxml.jackson.core.Version 实例源码

项目:spring-cloud-skipper    文件:Status.java   
@JsonIgnore
public List<AppStatus> getAppStatusList() {
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.addMixIn(AppStatus.class, AppStatusMixin.class);
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        SimpleModule module = new SimpleModule("CustomModel", Version.unknownVersion());
        SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver();
        resolver.addMapping(AppInstanceStatus.class, AppInstanceStatusImpl.class);
        module.setAbstractTypes(resolver);
        mapper.registerModule(module);
        TypeReference<List<AppStatus>> typeRef = new TypeReference<List<AppStatus>>() {
        };
        if (this.platformStatus != null) {
            return mapper.readValue(this.platformStatus, typeRef);
        }
        return new ArrayList<AppStatus>();
    }
    catch (Exception e) {
        throw new IllegalArgumentException("Could not parse Skipper Platfrom Status JSON:" + platformStatus, e);
    }
}
项目:crnk-framework    文件:JacksonModule.java   
/**
 * Creates Crnk Jackson module with all required serializers.<br />
 * Adds the {@link LinksInformationSerializer} if <code>serializeLinksAsObjects</code> is set to <code>true</code>.
 *
 * @param serializeLinksAsObjects flag which decides whether the {@link LinksInformationSerializer} should be added as
 * additional serializer or not.
 *
 * @return {@link com.fasterxml.jackson.databind.Module} with custom serializers
 */
public static SimpleModule createJacksonModule(boolean serializeLinksAsObjects) {
    SimpleModule simpleModule = new SimpleModule(JSON_API_JACKSON_MODULE_NAME,
            new Version(1, 0, 0, null, null, null));
    simpleModule.addSerializer(new ErrorDataSerializer());
    simpleModule.addDeserializer(ErrorData.class, new ErrorDataDeserializer());
    if (serializeLinksAsObjects) {
        simpleModule.addSerializer(new LinksInformationSerializer());
    }
    return simpleModule;
}
项目:Equella    文件:TinyMceServiceImpl.java   
private ObjectExpression getEditorOptions(HtmlEditorConfiguration config)
{
    final String options = config.getEditorOptions();
    if( options == null || options.trim().length() == 0 )
    {
        return null;
    }

    try
    {
        final ObjectMapper jsonMapper = objectMapperService.createObjectMapper(LenientMapperExtension.NAME);
        final SimpleModule module = new SimpleModule("equella", new Version(1, 0, 0, null));
        module.addDeserializer(ObjectExpression.class, new ObjectExpressionDeserialiser());
        jsonMapper.registerModule(module);
        final ObjectExpression obj = jsonMapper.readValue(options, ObjectExpression.class);
        return obj; // NOSONAR (kept local variable for readability)
    }
    catch( IOException io )
    {
        // Invalid editor options. Should never have happened.
        LOGGER.error("Invalid HTML editor options", io);
        return null;
    }
}
项目:Equella    文件:RestEasyServlet.java   
@Override
public void extendMapper(ObjectMapper mapper)
{
    SimpleModule restModule = new SimpleModule("RestModule", new Version(1, 0, 0, null));
    // TODO this probably should be somewhere else, but it can't be in
    // com.tle.core.jackson
    // as that would make it dependent on equella i18n
    restModule.addSerializer(new I18NSerializer());
    mapper.registerModule(restModule);
    mapper.registerModule(new JavaTypesModule());

    mapper.registerModule(new RestStringsModule());
    mapper.setSerializationInclusion(Include.NON_NULL);

    // dev mode!
    if( DebugSettings.isDebuggingMode() )
    {
        mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    }
    mapper.setDateFormat(new ISO8061DateFormatWithTZ());

}
项目:zefiro    文件:ZefiroModule.java   
public ZefiroModule() {
    super("ZefiroModule", new Version(majorVersion, minorVersion, patchLevel, null, "it.makeit.zefiro",
            "jersey-module-zefiro"));

    addSerializer(new ObjectTypeSerializer());
    addSerializer(new DocumentSerializer());
    addSerializer(new PropertySerializer());
    addSerializer(new RelationshipSerializer());

    // PropertyDefinition
    addSerializer(new PropertyDefinitionSerializer());
    addSerializer(new PropertyDecimalDefinitionSerializer());
    addSerializer(new PropertyIntegerDefinitionSerializer());
    addSerializer(new PropertyStringDefinitionSerializer());

    addDeserializer(DocumentPropertyBean.class, new DocumentPropertyDeserializer());
}
项目:simbest-cores    文件:JacksonObjectMapperConfig.java   
public JacksonObjectMapperConfig() {
    super();

    this.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);        
    //this.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); 不增加,避免key值为null,而避免节点消失
    this.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    this.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true); 

    //this.setSerializationInclusion(Include.NON_EMPTY); //对象转字符串时,只转化非空字段 zjs 需要占位

    //SimpleModule module = new SimpleModule();
       SimpleModule module = new SimpleModule("HTML XSS Serializer",
               new Version(1, 0, 0, "FINAL", "com.simbest", "ep-jsonmodule"));
       module.addSerializer(new JsonHtmlXssSerializer(String.class));
       module.addDeserializer(Date.class, new CustomJsonDateDeseralizer());
       // Add more here ...
       registerModule(module);
}
项目:graphql-spqr    文件:JacksonValueMapperFactory.java   
private Module getDeserializersModule(GlobalEnvironment environment) {
    return new Module() {
        @Override
        public String getModuleName() {
            return "graphql-spqr-deserializers";
        }

        @Override
        public Version version() {
            return Version.unknownVersion();
        }

        @Override
        public void setupModule(SetupContext setupContext) {
            setupContext.addDeserializers(new ConvertingDeserializers(environment));
        }
    };
}
项目:nbone    文件:JsonUtils.java   
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;
}
项目:allocateme    文件:ModelConversionHelper.java   
/**
 * Private method to register the custom serializers and deserializers
 */
private void init() {
    this.objectMapper = new ObjectMapper();
    SimpleModule module = new SimpleModule("UserProfileService",
            new Version(1, 0, 0, null, null, null));

    module.addSerializer(UserProfile.class, new UserProfileSerializer());
    module.addDeserializer(UserProfile.class, new UserProfileDeserializer());

    module.addSerializer(Publication.class, new PublicationSerializer());
    module.addDeserializer(Publication.class, new PublicationDeserializer());

    module.addSerializer(Institution.class, new InstitutionSerializer());
    module.addDeserializer(Institution.class, new InstitutionDeserializer());

    objectMapper.registerModule(module);
}
项目:elastic-rest-spring-wrapper    文件:RestClientConfig.java   
@Autowired
public void configObjectMapper(ObjectMapper objectMapper) {
    AggregationDeserializer deserializer = new AggregationDeserializer();
    deserializer.register("sterms", TermsAggregation.class);
    deserializer.register("histogram", HistogramAggregation.class);
    deserializer.register("date_histogram", DateHistogramAggregation.class);
    deserializer.register("avg", SingleValueMetricsAggregation.class);
    deserializer.register("sum", SingleValueMetricsAggregation.class);
    deserializer.register("max", SingleValueMetricsAggregation.class);
    deserializer.register("min", SingleValueMetricsAggregation.class);
    deserializer.register("cardinality", SingleValueMetricsAggregation.class);
    deserializer.register("value_count", SingleValueMetricsAggregation.class);


    SimpleModule module = new SimpleModule("AggregationDeserializer",
            new Version(1, 0, 0, null, "eu.luminis.elastic", "aggregation-elastic"));
    module.addDeserializer(Aggregation.class, deserializer);
    module.addKeyDeserializer(String.class, new AggregationKeyDeserializer());

    objectMapper.registerModule(module);
}
项目:step    文件:JacksonMapperProvider.java   
public static ObjectMapper createMapper() {
        ObjectMapper mapper = new ObjectMapper();
//        mapper.configure(AUTO_DETECT_GETTERS, false);
//        mapper.configure(AUTO_DETECT_SETTERS, false);
//        mapper.setDeserializationConfig(mapper.getDeserializationConfig().without(FAIL_ON_UNKNOWN_PROPERTIES));
//        mapper.setSerializationConfig(mapper.getSerializationConfig().withSerializationInclusion(NON_DEFAULT));
//        mapper.setVisibilityChecker(Std.defaultInstance().withFieldVisibility(ANY));
// 
        mapper.registerModule(new SimpleModule("jersey", new Version(1, 0, 0, null,null,null)) //
                        .addSerializer(_id, _idSerializer()) //
                        .addDeserializer(_id, _idDeserializer()));
        mapper.registerModule(new JSR353Module());
        mapper.registerModule(new JsonOrgModule());

        return mapper;
    }
项目:story-inspector    文件:JsonMappingSpringConfig.java   
/**
 * Generates an {@link ObjectMapper} to serialize and deserialize JSON.
 *
 * @return The generated {@link ObjectMapper}.
 */
@Bean
public ObjectMapper getDefaultObjectMapper() {
    final ObjectMapper mapper = new ObjectMapper();

    final SimpleModule module = new SimpleModule("AnalysisSerializers", new Version(1, 0, 0, null, null, null));

    // Add custom serializer & deserializer for AnalyzerType so that we can retrieve the correct singleton instance from spring
    module.addSerializer(AnalyzerType.class, new AnalyzerTypeSerializer());
    module.addDeserializer(AnalyzerType.class, new AnalyzerTypeDeserializer());

    // Add custom serializer & deserializer for Analyzer so that we can save the parameter values used to create the analyzer
    module.addSerializer(Analyzer.class, new AnalyzerSerializer());
    module.addDeserializer(Analyzer.class, new AnalyzerDeserializer());
    mapper.registerModule(module);

    // Save type information in JSON when declared type is object so it is deserialized correctly
    // Used because AnalyzerSpec has a map of string to object for saved parameter values
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT);

    return mapper;
}
项目:spring-cloud-dataflow    文件:SkipperStreamDeployer.java   
public static List<AppStatus> deserializeAppStatus(String platformStatus) {
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.addMixIn(AppStatus.class, AppStatusMixin.class);
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        SimpleModule module = new SimpleModule("CustomModel", Version.unknownVersion());
        SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver();
        resolver.addMapping(AppInstanceStatus.class, AppInstanceStatusImpl.class);
        module.setAbstractTypes(resolver);
        mapper.registerModule(module);
        TypeReference<List<AppStatus>> typeRef = new TypeReference<List<AppStatus>>() {
        };
        List<AppStatus> result = mapper.readValue(platformStatus, typeRef);
        return result;
    }
    catch (Exception e) {
        throw new IllegalArgumentException("Could not parse Skipper Platform Status JSON:" + platformStatus, e);
    }
}
项目:opencucina    文件:JacksonMarshaller.java   
/**
 * JAVADOC Method Level Comments
 *
 * @throws Exception JAVADOC.
 */
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void afterPropertiesSet()
    throws Exception {
    //Set up 
    SimpleModule module = new SimpleModule("user",
            new Version(1, 0, 0, "User serializer/deserializer", null, null));

    if (CollectionUtils.isNotEmpty(serialisers)) {
        for (JsonSerializer<?> serialiser : serialisers) {
            module.addSerializer(serialiser);
        }
    }

    if (MapUtils.isNotEmpty(deserialisers)) {
        for (Map.Entry<Class, JsonDeserializer> deserialiserEntry : deserialisers.entrySet()) {
            module.addDeserializer(deserialiserEntry.getKey(), deserialiserEntry.getValue());
        }
    }

    mapper.registerModule(module);
}
项目:Gaffer    文件:JSONSerialiserTest.java   
@Test
public void shouldUpdateInstanceWithCustomModule() throws Exception {
    // Given
    final JsonSerializer<String> serialiser = mock(JsonSerializer.class);
    TestCustomJsonModules1.modules = Collections.singletonList(
            new SimpleModule("module1", new Version(1, 0, 0, null, null, null))
                    .addSerializer(String.class, serialiser)
    );
    System.setProperty(JSONSerialiser.JSON_SERIALISER_MODULES, TestCustomJsonModules1.class.getName());

    // When
    JSONSerialiser.update();

    // Then
    assertEquals(JSONSerialiser.class, JSONSerialiser.getInstance().getClass());
    JSONSerialiser.serialise("test");
    verify(serialiser).serialize(Mockito.eq("test"), Mockito.any(), Mockito.any());
}
项目:Gaffer    文件:RoaringBitmapJsonSerialisationTest.java   
@Test
public void testCanSerialiseWithCustomObjectMapper() throws IOException {
    //Bitmap of (2,3000,300000) serialised in 0.5.11 Roaring Bitmap base 64 encoded
    String serialisedComparisonBitmap = "{\"roaringBitmap\":{\"value\":\"OjAAAAIAAAAAAAEABAAAABgAAAAcAAAAAgC4C+CT\"}}";
    RoaringBitmap comparisonBitmap = new RoaringBitmap();
    comparisonBitmap.add(2);
    comparisonBitmap.add(3000);
    comparisonBitmap.add(300000);
    final ObjectMapper mapper = JSONSerialiser.createDefaultMapper();
    final SimpleModule bitmapModule = new SimpleModule(RoaringBitmapConstants.BITMAP_MODULE_NAME, new Version(1, 0, 9, null, null, null));
    bitmapModule.addSerializer(RoaringBitmap.class, new RoaringBitmapJsonSerialiser());
    bitmapModule.addDeserializer(RoaringBitmap.class, new RoaringBitmapJsonDeserialiser());
    mapper.registerModule(bitmapModule);
    RoaringBitmap testBitmap = mapper.readValue(serialisedComparisonBitmap, RoaringBitmap.class);
    assertEquals(comparisonBitmap, testBitmap);
    String serialisedBitmap = mapper.writeValueAsString(testBitmap);
    assertEquals(serialisedBitmap, serialisedComparisonBitmap);
}
项目:netty-rest    文件:SwaggerReader.java   
public SwaggerReader(Swagger swagger, ObjectMapper mapper, BiConsumer<Method, Operation> swaggerOperationConsumer, Map<Class, PrimitiveType> externalTypes)
{
    this.swagger = swagger;
    modelConverters = new ModelConverters(mapper);
    this.swaggerOperationConsumer = swaggerOperationConsumer;
    modelConverters.addConverter(new ModelResolver(mapper));
    if (externalTypes != null) {
        setExternalTypes(externalTypes);
    }
    mapper.registerModule(
            new SimpleModule("swagger", Version.unknownVersion()) {
                @Override
                public void setupModule(SetupContext context) {
                    context.insertAnnotationIntrospector(new SwaggerJacksonAnnotationIntrospector());
                }
            });
    errorProperty = modelConverters.readAsProperty(HttpServer.ErrorMessage.class);
    swagger.addDefinition("ErrorMessage", modelConverters.read(HttpServer.ErrorMessage.class).entrySet().iterator().next().getValue());
}
项目:logsniffer    文件:CoreAppConfig.java   
@Bean
public ObjectMapper jsonObjectMapper() {
    final ObjectMapper jsonMapper = new ObjectMapper();
    jsonMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    jsonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    jsonMapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    jsonMapper.configure(Feature.ALLOW_SINGLE_QUOTES, true);
    jsonMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);

    final SimpleModule module = new SimpleModule("FieldsMapping", Version.unknownVersion());
    module.setSerializerModifier(new BeanSerializerModifier() {
        @Override
        public JsonSerializer<?> modifyMapSerializer(final SerializationConfig config, final MapType valueType,
                final BeanDescription beanDesc, final JsonSerializer<?> serializer) {
            if (FieldsMap.class.isAssignableFrom(valueType.getRawClass())) {
                return new FieldsMapMixInLikeSerializer();
            } else {
                return super.modifyMapSerializer(config, valueType, beanDesc, serializer);
            }
        }
    });
    jsonMapper.registerModule(module);
    return jsonMapper;
}
项目:astrix    文件:VersionedJsonObjectMapper.java   
private ObjectMapper buildMigratingMapper(ObjectMapper rawMapper, ThreadLocal<Integer> versionHolder) {
    SimpleModule module = new SimpleModule("Astrix-migratingModule", new Version(1, 0, 0, "", null, null));
    for (JsonMessageMigrator<?> migrator : this.migratorsByType.values()) {
        registerSerializerAndDeserializer(rawMapper, versionHolder, module, migrator);
    }
    // register custom serializers/deserializers for all custom types without migrator since those won't be intercepted by migratingObjectMapper
    for (JsonDeserializerHolder<?> deserializer : this.deserializers) {
        if (!this.migratorsByType.containsKey(deserializer.type)) {
            deserializer.register(module);
        }
    }
    for (JsonSerializerHolder<?> serializer : this.serializers) {
        if (!this.migratorsByType.containsKey(serializer.type)) {
            serializer.register(module);
        }
    }

    ObjectMapper result = new ObjectMapper();
    result.registerModule(module);
    return result;
}
项目:blcdemo    文件:RuleFieldExtractionUtility.java   
/**
 * Takes a JSON string that came from the frontend form submission and deserializes it into its {@link DataWrapper} dto
 * representation so that it can be converted to an MVEL expression
 * @param json
 * @return
 */
public DataWrapper convertJsonToDataWrapper(String json) {
    ObjectMapper mapper = new ObjectMapper();
    DataDTODeserializer dtoDeserializer = new DataDTODeserializer();
    SimpleModule module = new SimpleModule("DataDTODeserializerModule", new Version(1, 0, 0, null));
    module.addDeserializer(DataDTO.class, dtoDeserializer);
    mapper.registerModule(module);
    if (json == null || "[]".equals(json)) {
        return null;
    }

    try {
        return mapper.readValue(json, DataWrapper.class);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
项目:biweekly    文件:JCalModule.java   
private static Version moduleVersion() {
    String[] split = Biweekly.VERSION.split("[.-]");
    if (split.length < 3) {
        /*
         * This can happen during development if the "biweekly.properties"
         * file has not been filtered by Maven.
         */
        return new Version(0, 0, 0, "", Biweekly.GROUP_ID, Biweekly.ARTIFACT_ID);
    }

    int major = Integer.parseInt(split[0]);
    int minor = Integer.parseInt(split[1]);
    int patch = Integer.parseInt(split[2]);
    String snapshot = (split.length > 3) ? split[3] : "RELEASE";

    return new Version(major, minor, patch, snapshot, Biweekly.GROUP_ID, Biweekly.ARTIFACT_ID);
}
项目:QuizUpWinner    文件:VersionUtil.java   
public static Version parseVersion(String paramString1, String paramString2, String paramString3)
{
  if (paramString1 == null)
    return null;
  String str1 = paramString1.trim();
  if (str1.length() == 0)
    return null;
  String[] arrayOfString = VERSION_SEPARATOR.split(str1);
  int i = parseVersionPart(arrayOfString[0]);
  int j;
  if (arrayOfString.length > 1)
    j = parseVersionPart(arrayOfString[1]);
  else
    j = 0;
  int k;
  if (arrayOfString.length > 2)
    k = parseVersionPart(arrayOfString[2]);
  else
    k = 0;
  String str2;
  if (arrayOfString.length > 3)
    str2 = arrayOfString[3];
  else
    str2 = null;
  return new Version(i, j, k, str2, paramString2, paramString3);
}
项目:simple-spring-memcached    文件:JsonTranscoderTest.java   
@Test
public void testEncodeAndDecodeRegisterSerializerDirectlyToModule() {
    JsonObjectMapper mapper = new JsonObjectMapper();

    // first add serializer then register module
    SimpleModule module = new SimpleModule("cemo", Version.unknownVersion());
    module.addSerializer(Point.class, new PointSerializer());
    mapper.registerModule(module);

    transcoder = new JsonTranscoder(mapper);

    Point p = new Point(40, 50);

    CachedObject co = transcoder.encode(p);
    assertNotNull(co);
    assertNotNull(co.getData());
    assertEquals("{\"v\":\"40x50\"}", new String(co.getData()));
}
项目:Beam    文件:VersionUtil.java   
protected VersionUtil()
{
    Version v = null;
    try {
        /* Class we pass only matters for resource-loading: can't use this Class
         * (as it's just being loaded at this point), nor anything that depends on it.
         */
        v = VersionUtil.versionFor(getClass());
    } catch (Exception e) { // not good to dump to stderr; but that's all we have at this low level
        System.err.println("ERROR: Failed to load Version information from "+getClass());
    }
    if (v == null) {
        v = Version.unknownVersion();
    }
    _version = v;
}
项目:Beam    文件:VersionUtil.java   
/**
 * Helper method that will try to load version information for specified
 * class. Implementation is as follows:
 *
 * First, tries to load version info from a class named
 * "PackageVersion" in the same package as the class.
 *
 * Next, if that fails, class loader that loaded specified class is
 * asked to load resource with name "VERSION" from same location
 * (package) as class itself had.
 *
 * If no version information is found, {@link Version#unknownVersion()} is returned.
 */
@SuppressWarnings("resource")
public static Version versionFor(Class<?> cls)
{
    Version packageVersion = packageVersionFor(cls);
    if (packageVersion != null) {
        return packageVersion;
    }
    final InputStream in = cls.getResourceAsStream("VERSION.txt");
    if (in == null) {
        return Version.unknownVersion();
    }
    try {
        InputStreamReader reader = new InputStreamReader(in, "UTF-8");
        return doReadVersion(reader);
    } catch (UnsupportedEncodingException e) {
        return Version.unknownVersion();
    } finally {
        _close(in);
    }
}
项目:Beam    文件:VersionUtil.java   
private static Version doReadVersion(final Reader reader)
{
    String version = null, group = null, artifact = null;

    final BufferedReader br = new BufferedReader(reader);
    try {
        version = br.readLine();
        if (version != null) {
            group = br.readLine();
            if (group != null) {
                artifact = br.readLine();
            }
        }
    } catch (IOException ignored) {
    } finally {
        _close(br);
    }
    // We don't trim() version: parseVersion() takes care ot that
    if (group != null) {
        group = group.trim();
    }
    if (artifact != null) {
        artifact = artifact.trim();
    }
    return parseVersion(version, group, artifact);
}
项目:Beam    文件:VersionUtil.java   
/**
 * Will attempt to load the maven version for the given groupId and
 * artifactId.  Maven puts a pom.properties file in
 * META-INF/maven/groupId/artifactId, containing the groupId,
 * artifactId and version of the library.
 *
 * @param classLoader the ClassLoader to load the pom.properties file from
 * @param groupId the groupId of the library
 * @param artifactId the artifactId of the library
 * @return The version
 */
@SuppressWarnings("resource")
public static Version mavenVersionFor(ClassLoader classLoader, String groupId, String artifactId)
{
    InputStream pomProperties = classLoader.getResourceAsStream("META-INF/maven/"
            + groupId.replaceAll("\\.", "/")+ "/" + artifactId + "/pom.properties");
    if (pomProperties != null) {
        try {
            Properties props = new Properties();
            props.load(pomProperties);
            String versionStr = props.getProperty("version");
            String pomPropertiesArtifactId = props.getProperty("artifactId");
            String pomPropertiesGroupId = props.getProperty("groupId");
            return parseVersion(versionStr, pomPropertiesGroupId, pomPropertiesArtifactId);
        } catch (IOException e) {
            // Ignore
        } finally {
            _close(pomProperties);
        }
    }
    return Version.unknownVersion();
}
项目:cougar    文件:JSONBindingFactory.java   
/**
 * Fixes problem in Jackson's StdDeserializer. with _parseInteger and _parseLong.
 * The provided implementation allowed out-of-range numbers to be shoe-horned into types, ignoring under/overflow.
 * E.g. 21474836470 would be deserialized into an Integer as -10.
 * E.g. 92233720368547758080 would be deserialized into a Long as 0.
 */
private static void applyNumericRangeBugfixes(ObjectMapper mapper) {
    // Create a custom module
    SimpleModule customModule = new SimpleModule("CustomModule", new Version(1, 0, 0, null, null, null));
    // Register a deserializer for Integer that overrides default buggy version
    customModule.addDeserializer(Integer.class, new IntegerDeserializer());
    customModule.addDeserializer(int.class, new IntegerDeserializer());
    // Register a deserializer for Long that overrides default buggy version
    customModule.addDeserializer(Long.class, new LongDeserializer());
    customModule.addDeserializer(long.class, new LongDeserializer());
    // Register a deserializer for Byte that overrides default buggy version
    customModule.addDeserializer(Byte.class, new ByteDeserializer());
    customModule.addDeserializer(byte.class, new ByteDeserializer());
    // Add the module to the mapper
    mapper.registerModule(customModule);
}
项目:gwt-jackson    文件:ObjectifyJacksonModule.java   
public ObjectifyJacksonModule() {
    super( "Objectify", Version.unknownVersion() );

    // Objectify Key
    addSerializer( Key.class, new KeyStdSerializer() );
    addDeserializer( Key.class, new KeyStdDeserializer() );
    addKeySerializer( Key.class, new KeyJsonSerializer() );
    addKeyDeserializer( Key.class, new KeyStdKeyDeserializer() );

    // Objectify Ref
    addSerializer( Ref.class, new RefStdSerializer() );
    addDeserializer( Ref.class, new RefStdDeserializer() );
    addKeySerializer( Ref.class, new RefJsonSerializer() );
    addKeyDeserializer( Ref.class, new RefStdKeyDeserializer() );

    // Native datastore Key
    addSerializer( com.google.appengine.api.datastore.Key.class, new RawKeyStdSerializer() );
    addDeserializer( com.google.appengine.api.datastore.Key.class, new RawKeyStdDeserializer() );
    addKeySerializer( com.google.appengine.api.datastore.Key.class, new RawKeyJsonSerializer() );
    addKeyDeserializer( com.google.appengine.api.datastore.Key.class, new RawKeyStdKeyDeserializer() );
}
项目:temporary-groupdocs-java-sdk    文件:ApiInvoker.java   
@SuppressWarnings("unchecked")
public static Object deserialize(String json, String containerType, @SuppressWarnings("rawtypes") Class cls) throws ApiException {
    try{
      ObjectMapper mapper = JsonUtil.getJsonMapper();
      SimpleModule m = new SimpleModule(PACKAGE_NAME, Version.unknownVersion());
      m.addDeserializer(Date.class, new CustomDateDeserializer(new DateDeserializer()));
      mapper.registerModule(m);

      if("List".equals(containerType)) {
        JavaType typeInfo = mapper.getTypeFactory().constructCollectionType(List.class, cls);
        List<?> response = (List<?>) mapper.readValue(json, typeInfo);
        return response;
      }
      else if(String.class.equals(cls)) {
        return json;
      }
      else {
        return mapper.readValue(json, cls);
      }
    }
    catch (IOException e) {
      throw new ApiException(500, e.getMessage());
    }
  }
项目:rdap    文件:CustomObjectMapper.java   
public CustomObjectMapper() {
  super.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
  setSerializationInclusion(JsonInclude.Include.NON_NULL);
  configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
  configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
  SimpleModule simpleModule = new SimpleModule("SimpleModule",
      new Version(1, 0, 0, null));

  simpleModule.addSerializer(new RDAPContactSerializer());
  simpleModule.addSerializer(new StructuredValueSerializer());
  simpleModule.addSerializer(new TextListSerializer());
  simpleModule.addSerializer(new TextSerializer());
  simpleModule.addSerializer(new URIValueSerializer());
  simpleModule.addSerializer(new DomainNameSerializer());
  simpleModule.addSerializer(new DateTimeSerializer());
  simpleModule.addSerializer(new StatusSerializer());
  for (JsonSerializer serializer: getSerializers()) {
    simpleModule.addSerializer(serializer);
  }

  registerModule(simpleModule);
}
项目:groupdocs-java    文件:ApiInvoker.java   
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
  try{
    ObjectMapper mapper = JsonUtil.getJsonMapper();
 SimpleModule m = new SimpleModule(PACKAGE_NAME, Version.unknownVersion());
 m.addDeserializer(Date.class, new CustomDateDeserializer(new DateDeserializer()));
 mapper.registerModule(m);

    if("List".equals(containerType)) {
      JavaType typeInfo = mapper.getTypeFactory().constructCollectionType(List.class, cls);
      List response = (List<?>) mapper.readValue(json, typeInfo);
      return response;
    }
    else if(String.class.equals(cls)) {
      return json;
    }
    else {
      return mapper.readValue(json, cls);
    }
  }
  catch (IOException e) {
    throw new ApiException(500, e.getMessage());
  }
}
项目:alfresco-mvc    文件:Jackson2PostProcessor.java   
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
  if (bean instanceof RequestMappingHandlerAdapter) {
    RequestMappingHandlerAdapter adapter = (RequestMappingHandlerAdapter) bean;
    List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
    for (HttpMessageConverter<?> converter : converters) {
      if (converter instanceof MappingJackson2HttpMessageConverter) {
        MappingJackson2HttpMessageConverter jsonConverter = (MappingJackson2HttpMessageConverter) converter;

        ObjectMapper objectMapper = new ObjectMapper();
        SimpleModule module = new SimpleModule("Alfresco MVC Module", new Version(1, 0, 0, null, null, null));
        module.addSerializer(QName.class, new Jackson2QnameSerializer(serviceRegistry));
        module.addDeserializer(QName.class, new Jackson2QnameDeserializer(serviceRegistry));

        objectMapper.setDateFormat(new SimpleDateFormat(getDateFormat()));
        objectMapper.registerModule(module);

        jsonConverter.setObjectMapper(objectMapper);
      }
    }
  }
  return bean;
}
项目:bandwidth-on-demand    文件:AppComponents.java   
@Bean
public ObjectMapper jacksonObjectMapper() {
  ObjectMapper mapper = new ObjectMapper();

  mapper.setVisibility(
      mapper.getSerializationConfig().getDefaultVisibilityChecker()
          .withFieldVisibility(Visibility.ANY)
          .withGetterVisibility(Visibility.NONE)
          .withSetterVisibility(Visibility.NONE)
          .withCreatorVisibility(Visibility.NONE)
          .withIsGetterVisibility(Visibility.NONE));
  SimpleModule module = new SimpleModule("bandwidth-on-demand", Version.unknownVersion());
  module.addSerializer(new VlanJsonSerializer());
  module.addDeserializer(Vlan.class, new VlanJsonDeserializer());
  module.addSerializer(new ScheduleTypeJsonSerializer());
  module.addDeserializer(ScheduleType.class, new ScheduleTypeJsonDeserializer());
  mapper.registerModule(module);
  mapper.registerModule(new Hibernate4Module());
  mapper.registerModule(new JodaModule());
  mapper.registerModule(new Jdk8Module());
  mapper.registerModule(new JavaTimeModule());
  mapper.registerSubtypes(new NamedType(LocalVirtualPort.class, "LOCAL"));
  mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);

  return mapper;
}
项目:joyplus-tv    文件:VersionUtil.java   
protected VersionUtil()
{
    Version v = null;
    try {
        /* Class we pass only matters for resource-loading: can't use this Class
         * (as it's just being loaded at this point), nor anything that depends on it.
         */
        v = VersionUtil.versionFor(getClass());
    } catch (Exception e) { // not good to dump to stderr; but that's all we have at this low level
        System.err.println("ERROR: Failed to load Version information for bundle (via "+getClass().getName()+").");
    }
    if (v == null) {
        v = Version.unknownVersion();
    }
    _version = v;
}
项目:joyplus-tv    文件:VersionUtil.java   
public static Version parseVersion(String versionStr, String groupId, String artifactId)
{
    if (versionStr == null) {
        return null;
    }
    versionStr = versionStr.trim();
    if (versionStr.length() == 0) {
        return null;
    }
    String[] parts = VERSION_SEPARATOR.split(versionStr);
    int major = parseVersionPart(parts[0]);
    int minor = (parts.length > 1) ? parseVersionPart(parts[1]) : 0;
    int patch = (parts.length > 2) ? parseVersionPart(parts[2]) : 0;
    String snapshot = (parts.length > 3) ? parts[3] : null;

    return new Version(major, minor, patch, snapshot,
            groupId, artifactId);
}
项目:joynr    文件:AbstractBounceProxyServerTest.java   
private ObjectMapper getObjectMapper() {
    objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
    // objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS,
    // true);
    objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, true);
    objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);

    objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName");
    TypeResolverBuilder<?> joynrTypeResolverBuilder = objectMapper.getSerializationConfig()
                                                                  .getDefaultTyper(SimpleType.construct(Object.class));

    SimpleModule module = new SimpleModule("NonTypedModule", new Version(1, 0, 0, "", "", ""));
    module.addSerializer(new JoynrEnumSerializer());
    module.addSerializer(new JoynrListSerializer());

    TypeDeserializer typeDeserializer = joynrTypeResolverBuilder.buildTypeDeserializer(objectMapper.getDeserializationConfig(),
                                                                                       SimpleType.construct(Object.class),
                                                                                       null);

    module.addDeserializer(Object.class, new JoynrUntypedObjectDeserializer(typeDeserializer));
    objectMapper.registerModule(module);
    return objectMapper;
}
项目:GitHub    文件:VersionUtil.java   
/**
 * Method used by <code>PackageVersion</code> classes to decode version injected by Maven build.
 */
public static Version parseVersion(String s, String groupId, String artifactId)
{
    if (s != null && (s = s.trim()).length() > 0) {
        String[] parts = V_SEP.split(s);
        return new Version(parseVersionPart(parts[0]),
                (parts.length > 1) ? parseVersionPart(parts[1]) : 0,
                (parts.length > 2) ? parseVersionPart(parts[2]) : 0,
                (parts.length > 3) ? parts[3] : null,
                groupId, artifactId);
    }
    return Version.unknownVersion();
}
项目:beadledom    文件:AvroJacksonModule.java   
@Inject
AvroJacksonModule(BuildInfo buildInfo) {
  Matcher versionMatcher = Pattern.compile("\\A(\\d+)\\.(\\d+)(\\.(\\d+))?.*").matcher(buildInfo.getVersion());
  checkState(versionMatcher.matches(), "artifact version could not be parsed: " + buildInfo.getVersion());
  int majorVersion = Integer.parseInt(versionMatcher.group(1));
  int minorVersion = Integer.parseInt(versionMatcher.group(2));
  int fixVersion = versionMatcher.group(4) == null ? 0 : Integer.parseInt(versionMatcher.group(4));

  String[] versionSplit = buildInfo.getVersion().split("-", 2);
  String snapshotInfo = versionSplit.length > 1 ? versionSplit[1] : null;

  this.version = new Version(majorVersion, minorVersion, fixVersion, snapshotInfo, buildInfo.getGroupId(), buildInfo.getArtifactId());
}