Search in sources :

Example 11 with NamedType

use of com.fasterxml.jackson.databind.jsontype.NamedType in project jackson-databind by FasterXML.

the class BeanSerializerFactory method findPropertyContentTypeSerializer.

/**
     * Method called to create a type information serializer for values of given
     * container property
     * if one is needed. If not needed (no polymorphic handling configured), should
     * return null.
     *
     * @param containerType Declared type of the container to use as the base type for type information serializer
     * 
     * @return Type serializer to use for property value contents, if one is needed; null if not.
     */
public TypeSerializer findPropertyContentTypeSerializer(JavaType containerType, SerializationConfig config, AnnotatedMember accessor) throws JsonMappingException {
    JavaType contentType = containerType.getContentType();
    AnnotationIntrospector ai = config.getAnnotationIntrospector();
    TypeResolverBuilder<?> b = ai.findPropertyContentTypeResolver(config, accessor, containerType);
    TypeSerializer typeSer;
    // Defaulting: if no annotations on member, check value class
    if (b == null) {
        typeSer = createTypeSerializer(config, contentType);
    } else {
        Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass(config, accessor, contentType);
        typeSer = b.buildTypeSerializer(config, contentType, subtypes);
    }
    return typeSer;
}
Also used : NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) TypeSerializer(com.fasterxml.jackson.databind.jsontype.TypeSerializer)

Example 12 with NamedType

use of com.fasterxml.jackson.databind.jsontype.NamedType in project jackson-databind by FasterXML.

the class JacksonAnnotationIntrospector method findSubtypes.

@Override
public List<NamedType> findSubtypes(Annotated a) {
    JsonSubTypes t = _findAnnotation(a, JsonSubTypes.class);
    if (t == null)
        return null;
    JsonSubTypes.Type[] types = t.value();
    ArrayList<NamedType> result = new ArrayList<NamedType>(types.length);
    for (JsonSubTypes.Type type : types) {
        result.add(new NamedType(type.value(), type.name()));
    }
    return result;
}
Also used : NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) MapLikeType(com.fasterxml.jackson.databind.type.MapLikeType) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType)

Example 13 with NamedType

use of com.fasterxml.jackson.databind.jsontype.NamedType in project jackson-databind by FasterXML.

the class TestSubtypes method testDeserializatioNamed.

public void testDeserializatioNamed() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerSubtypes(SubB.class);
    mapper.registerSubtypes(new NamedType(SubD.class, "TypeD"));
    SuperType bean = mapper.readValue("{\"@type\":\"TypeB\", \"b\":13}", SuperType.class);
    assertSame(SubB.class, bean.getClass());
    assertEquals(13, ((SubB) bean).b);
    // but we can also explicitly register name too
    bean = mapper.readValue("{\"@type\":\"TypeD\", \"d\":-4}", SuperType.class);
    assertSame(SubD.class, bean.getClass());
    assertEquals(-4, ((SubD) bean).d);
}
Also used : NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 14 with NamedType

use of com.fasterxml.jackson.databind.jsontype.NamedType in project druid by druid-io.

the class IndexGeneratorJobTest method setUp.

@Before
public void setUp() throws Exception {
    mapper = HadoopDruidIndexerConfig.JSON_MAPPER;
    mapper.registerSubtypes(new NamedType(HashBasedNumberedShardSpec.class, "hashed"));
    mapper.registerSubtypes(new NamedType(SingleDimensionShardSpec.class, "single"));
    dataFile = temporaryFolder.newFile();
    tmpDir = temporaryFolder.newFolder();
    HashMap<String, Object> inputSpec = new HashMap<String, Object>();
    inputSpec.put("paths", dataFile.getCanonicalPath());
    inputSpec.put("type", "static");
    if (inputFormatName != null) {
        inputSpec.put("inputFormat", inputFormatName);
    }
    if (SequenceFileInputFormat.class.getName().equals(inputFormatName)) {
        writeDataToLocalSequenceFile(dataFile, data);
    } else {
        FileUtils.writeLines(dataFile, data);
    }
    config = new HadoopDruidIndexerConfig(new HadoopIngestionSpec(new DataSchema(datasourceName, mapper.convertValue(inputRowParser, Map.class), aggs, new UniformGranularitySpec(Granularities.DAY, Granularities.NONE, ImmutableList.of(this.interval)), mapper), new HadoopIOConfig(ImmutableMap.copyOf(inputSpec), null, tmpDir.getCanonicalPath()), new HadoopTuningConfig(tmpDir.getCanonicalPath(), null, null, null, null, maxRowsInMemory, false, false, false, false, //verifies that set num reducers is ignored
    ImmutableMap.of(JobContext.NUM_REDUCES, "0"), false, useCombiner, null, buildV9Directly, null, forceExtendableShardSpecs, false)));
    config.setShardSpecs(loadShardSpecs(partitionType, shardInfoForEachSegment));
    config = HadoopDruidIndexerConfig.fromSpec(config.getSchema());
}
Also used : HashBasedNumberedShardSpec(io.druid.timeline.partition.HashBasedNumberedShardSpec) HashMap(java.util.HashMap) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) SequenceFileInputFormat(org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat) DataSchema(io.druid.segment.indexing.DataSchema) UniformGranularitySpec(io.druid.segment.indexing.granularity.UniformGranularitySpec) SingleDimensionShardSpec(io.druid.timeline.partition.SingleDimensionShardSpec) Before(org.junit.Before)

Example 15 with NamedType

use of com.fasterxml.jackson.databind.jsontype.NamedType in project druid by druid-io.

the class OrcIndexGeneratorJobTest method setUp.

@Before
public void setUp() throws Exception {
    mapper = HadoopDruidIndexerConfig.JSON_MAPPER;
    mapper.registerSubtypes(new NamedType(HashBasedNumberedShardSpec.class, "hashed"));
    dataRoot = temporaryFolder.newFolder("data");
    outputRoot = temporaryFolder.newFolder("output");
    File dataFile = writeDataToLocalOrcFile(dataRoot, data);
    HashMap<String, Object> inputSpec = new HashMap<String, Object>();
    inputSpec.put("paths", dataFile.getCanonicalPath());
    inputSpec.put("type", "static");
    inputSpec.put("inputFormat", "org.apache.hadoop.hive.ql.io.orc.OrcNewInputFormat");
    config = new HadoopDruidIndexerConfig(new HadoopIngestionSpec(new DataSchema(dataSourceName, mapper.convertValue(inputRowParser, Map.class), aggs, new UniformGranularitySpec(Granularities.DAY, Granularities.NONE, ImmutableList.of(this.interval)), mapper), new HadoopIOConfig(ImmutableMap.copyOf(inputSpec), null, outputRoot.getCanonicalPath()), new HadoopTuningConfig(outputRoot.getCanonicalPath(), null, null, null, null, null, false, false, false, false, //verifies that set num reducers is ignored
    ImmutableMap.of(JobContext.NUM_REDUCES, "0"), false, true, null, true, null, false, false)));
    config.setShardSpecs(loadShardSpecs(shardInfoForEachSegment));
    config = HadoopDruidIndexerConfig.fromSpec(config.getSchema());
}
Also used : HashBasedNumberedShardSpec(io.druid.timeline.partition.HashBasedNumberedShardSpec) HadoopIngestionSpec(io.druid.indexer.HadoopIngestionSpec) HashMap(java.util.HashMap) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) HadoopTuningConfig(io.druid.indexer.HadoopTuningConfig) HadoopDruidIndexerConfig(io.druid.indexer.HadoopDruidIndexerConfig) HadoopIOConfig(io.druid.indexer.HadoopIOConfig) DataSchema(io.druid.segment.indexing.DataSchema) UniformGranularitySpec(io.druid.segment.indexing.granularity.UniformGranularitySpec) OrcFile(org.apache.orc.OrcFile) File(java.io.File) Before(org.junit.Before)

Aggregations

NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)27 AnnotationIntrospector (com.fasterxml.jackson.databind.AnnotationIntrospector)4 JavaType (com.fasterxml.jackson.databind.JavaType)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ApiModel (io.swagger.annotations.ApiModel)3 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)2 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)2 TypeSerializer (com.fasterxml.jackson.databind.jsontype.TypeSerializer)2 DataSchema (io.druid.segment.indexing.DataSchema)2 UniformGranularitySpec (io.druid.segment.indexing.granularity.UniformGranularitySpec)2 HashBasedNumberedShardSpec (io.druid.timeline.partition.HashBasedNumberedShardSpec)2 ApiModelProperty (io.swagger.annotations.ApiModelProperty)2 ComposedModel (io.swagger.models.ComposedModel)2 Model (io.swagger.models.Model)2 ModelImpl (io.swagger.models.ModelImpl)2 RefModel (io.swagger.models.RefModel)2 AbstractNumericProperty (io.swagger.models.properties.AbstractNumericProperty)2 ArrayProperty (io.swagger.models.properties.ArrayProperty)2