Search in sources :

Example 6 with Version

use of com.fasterxml.jackson.core.Version in project Gaffer by gchq.

the class RoaringBitmapJsonSerialisationTest method testCanSerialiseWithCustomObjectMapper.

@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);
}
Also used : Version(com.fasterxml.jackson.core.Version) RoaringBitmap(org.roaringbitmap.RoaringBitmap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) Test(org.junit.Test)

Example 7 with Version

use of com.fasterxml.jackson.core.Version in project jackson-core by FasterXML.

the class VersionUtil method packageVersionFor.

/**
     * Loads version information by introspecting a class named
     * "PackageVersion" in the same package as the given class.
     *<p>
     * If the class could not be found or does not have a public
     * static Version field named "VERSION", returns null.
     */
public static Version packageVersionFor(Class<?> cls) {
    Version v = null;
    try {
        String versionInfoClassName = cls.getPackage().getName() + ".PackageVersion";
        Class<?> vClass = Class.forName(versionInfoClassName, true, cls.getClassLoader());
        // However, if class exists, it better work correctly, no swallowing exceptions
        try {
            v = ((Versioned) vClass.newInstance()).version();
        } catch (Exception e) {
            throw new IllegalArgumentException("Failed to get Versioned out of " + vClass);
        }
    } catch (Exception e) {
        // ok to be missing (not good but acceptable)
        ;
    }
    return (v == null) ? Version.unknownVersion() : v;
}
Also used : Version(com.fasterxml.jackson.core.Version)

Example 8 with Version

use of com.fasterxml.jackson.core.Version in project jackson-databind by FasterXML.

the class IntrospectorPairTest method testVersion.

public void testVersion() throws Exception {
    Version v = new Version(1, 2, 3, null, "com.fasterxml", "IntrospectorPairTest");
    IntrospectorWithMap withVersion = new IntrospectorWithMap().version(v);
    assertEquals(v, new AnnotationIntrospectorPair(withVersion, NO_ANNOTATIONS).version());
    assertEquals(Version.unknownVersion(), new AnnotationIntrospectorPair(NO_ANNOTATIONS, withVersion).version());
}
Also used : Version(com.fasterxml.jackson.core.Version)

Example 9 with Version

use of com.fasterxml.jackson.core.Version in project hadoop by apache.

the class StatePool method write.

private void write(DataOutput out) throws IOException {
    // This is just a JSON experiment
    System.out.println("Dumping the StatePool's in JSON format.");
    ObjectMapper outMapper = new ObjectMapper();
    // define a module
    SimpleModule module = new SimpleModule("State Serializer", new Version(0, 1, 1, "FINAL", "", ""));
    // add the state serializer
    //module.addSerializer(State.class, new StateSerializer());
    // register the module with the object-mapper
    outMapper.registerModule(module);
    JsonFactory outFactory = outMapper.getFactory();
    JsonGenerator jGen = outFactory.createGenerator((DataOutputStream) out, JsonEncoding.UTF8);
    jGen.useDefaultPrettyPrinter();
    jGen.writeObject(this);
    jGen.close();
}
Also used : Version(com.fasterxml.jackson.core.Version) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 10 with Version

use of com.fasterxml.jackson.core.Version in project hadoop by apache.

the class Anonymizer method initialize.

private void initialize(String[] args) throws Exception {
    try {
        for (int i = 0; i < args.length; ++i) {
            if ("-trace".equals(args[i])) {
                anonymizeTrace = true;
                inputTracePath = new Path(args[i + 1]);
                outputTracePath = new Path(args[i + 2]);
                i += 2;
            }
            if ("-topology".equals(args[i])) {
                anonymizeTopology = true;
                inputTopologyPath = new Path(args[i + 1]);
                outputTopologyPath = new Path(args[i + 2]);
                i += 2;
            }
        }
    } catch (Exception e) {
        throw new IllegalArgumentException("Illegal arguments list!", e);
    }
    if (!anonymizeTopology && !anonymizeTrace) {
        throw new IllegalArgumentException("Invalid arguments list!");
    }
    statePool = new StatePool();
    // initialize the state manager after the anonymizers are registered
    statePool.initialize(getConf());
    outMapper = new ObjectMapper();
    // define a module
    SimpleModule module = new SimpleModule("Anonymization Serializer", new Version(0, 1, 1, "FINAL", "", ""));
    // add various serializers to the module
    // use the default (as-is) serializer for default data types
    module.addSerializer(DataType.class, new DefaultRumenSerializer());
    // use a blocking serializer for Strings as they can contain sensitive 
    // information
    module.addSerializer(String.class, new BlockingSerializer());
    // use object.toString() for object of type ID
    module.addSerializer(ID.class, new ObjectStringSerializer<ID>());
    // use getAnonymizedValue() for data types that have the anonymizing 
    // feature
    module.addSerializer(AnonymizableDataType.class, new DefaultAnonymizingRumenSerializer(statePool, getConf()));
    // register the module with the object-mapper
    outMapper.registerModule(module);
    outFactory = outMapper.getFactory();
}
Also used : Path(org.apache.hadoop.fs.Path) IOException(java.io.IOException) Version(com.fasterxml.jackson.core.Version) ID(org.apache.hadoop.mapreduce.ID) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Aggregations

Version (com.fasterxml.jackson.core.Version)12 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 JsonParser (com.fasterxml.jackson.core.JsonParser)1 PackageVersion (com.fasterxml.jackson.databind.cfg.PackageVersion)1 CmsSystemCodeSerializer (gov.ca.cwds.data.CmsSystemCodeSerializer)1 IOException (java.io.IOException)1 Path (org.apache.hadoop.fs.Path)1 ID (org.apache.hadoop.mapreduce.ID)1 Before (org.junit.Before)1 Test (org.junit.Test)1 RoaringBitmap (org.roaringbitmap.RoaringBitmap)1