Example usage for com.fasterxml.jackson.databind.module SimpleModule SimpleModule

List of usage examples for com.fasterxml.jackson.databind.module SimpleModule SimpleModule

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.module SimpleModule SimpleModule.

Prototype

public SimpleModule() 

Source Link

Document

Constructors that should only be used for non-reusable convenience modules used by app code: "real" modules should use actual name and version number information.

Usage

From source file:pl.edu.pwr.iiar.zak.thermalKit.ThermalDesign.ThermalUnitsFactory.java

/**
 * TODO: description// w w  w .ja  v  a  2s .  c  om
 */
private void loadThermometerCollection() {
    SimpleModule module = new SimpleModule();
    module.addDeserializer(ThermometerUnit.class, new ThermometerUnitDeserializer());
    Jongo jongo = new Jongo(db, new JacksonMapper.Builder().registerModule(module).build());

    thermometersDBCollection = jongo.getCollection(parser.getThermometersCollection(deviceFamily));
}

From source file:org.apache.streams.monitoring.tasks.BroadcastMonitorThread.java

/**
 * Initialize our object mapper with all of our bean's custom deserializers
 * This way we can convert them to and from Strings dictated by our
 * POJOs which are generated from JSON schemas
 */// ww  w  .j a  v  a2 s  . c  o m
private void initializeObjectMapper() {
    objectMapper = StreamsJacksonMapper.getInstance();
    SimpleModule simpleModule = new SimpleModule();

    simpleModule.addDeserializer(MemoryUsageBroadcast.class, new MemoryUsageDeserializer());
    simpleModule.addDeserializer(ThroughputQueueBroadcast.class, new ThroughputQueueDeserializer());
    simpleModule.addDeserializer(StreamsTaskCounterBroadcast.class, new StreamsTaskCounterDeserializer());
    simpleModule.addDeserializer(DatumStatusCounterBroadcast.class, new DatumStatusCounterDeserializer());

    objectMapper.registerModule(simpleModule);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}

From source file:aptgraph.server.JsonRpcServer.java

/**
 * Start the server, blocking. This method will only return if the server
 * crashed.../*  w  w w .j a v a 2s  . c o  m*/
 * @throws java.io.IOException if the graph file cannot be read
 * @throws java.lang.ClassNotFoundException if the Graph class is not found
 * @throws java.lang.Exception if the server cannot start...
 */
public final void start() throws IOException, ClassNotFoundException, Exception {

    LOGGER.info("Reading graphs from disk...");
    ObjectInputStream input = new ObjectInputStream(new BufferedInputStream(input_file));
    HashMap<String, LinkedList<Graph<Request>>> user_graphs = (HashMap<String, LinkedList<Graph<Request>>>) input
            .readObject();
    input.close();

    Map.Entry<String, LinkedList<Graph<Request>>> entry_set = user_graphs.entrySet().iterator().next();
    String first_key = entry_set.getKey();
    LOGGER.log(Level.INFO, "Graph has {0} features", user_graphs.get(first_key).size());
    LOGGER.log(Level.INFO, "k-NN Graph : k = {0}", user_graphs.get(first_key).getFirst().getK());
    LOGGER.log(Level.INFO, "Starting JSON-RPC server at http://{0}:{1}",
            new Object[] { config.getServerHost(), config.getServerPort() });

    RequestHandler request_handler = new RequestHandler(user_graphs);

    ObjectMapper object_mapper = new ObjectMapper();
    SimpleModule module = new SimpleModule();
    module.addSerializer(Graph.class, new GraphSerializer());
    module.addSerializer(Domain.class, new DomainSerializer());
    module.addSerializer(Neighbor.class, new NeighborSerializer());
    object_mapper.registerModule(module);

    com.googlecode.jsonrpc4j.JsonRpcServer jsonrpc_server = new com.googlecode.jsonrpc4j.JsonRpcServer(
            object_mapper, request_handler);

    QueuedThreadPool thread_pool = new QueuedThreadPool(config.getMaxThreads(), config.getMinThreads(),
            config.getIdleTimeout(), new ArrayBlockingQueue<Runnable>(config.getMaxPendingRequests()));

    http_server = new org.eclipse.jetty.server.Server(thread_pool);
    //http_server = new org.eclipse.jetty.server.Server();

    ServerConnector http_connector = new ServerConnector(http_server);
    http_connector.setHost(config.getServerHost());
    http_connector.setPort(config.getServerPort());

    http_server.setConnectors(new Connector[] { http_connector });
    http_server.setHandler(new JettyHandler(jsonrpc_server));

    http_server.start();
}

From source file:org.wisdom.monitor.extensions.jcr.script.JcrScriptExecutorExtension.java

@Route(method = HttpMethod.GET, uri = "")
public Result index() throws Exception {
    Session session = jcrRepository.getSession();
    Optional<String> currentMigrationWorkspaceOptional = Arrays
            .asList(session.getWorkspace().getAccessibleWorkspaceNames()).stream()
            .filter(name -> name.startsWith(JCR_MIGRATION_PREFIX)).findFirst();
    String workspace = "";
    String script = "";
    List<Event> events = new ArrayList<>();
    if (currentMigrationWorkspaceOptional.isPresent()) {
        workspace = currentMigrationWorkspaceOptional.get();
        Node rootNode = session.getRepository().login(workspace).getRootNode();
        if (rootNode.hasNode("jcr:migrations")) {
            Node migrationNode = rootNode.getNode("jcr:migrations").getNode(workspace);
            script = migrationNode.getProperty("script").getString();
            ObjectMapper mapper = new ObjectMapper();
            SimpleModule module = new SimpleModule();
            module.addDeserializer(Event.class, new JcrEventDeserializer());
            mapper.registerModule(module);
            events = mapper.readValue(migrationNode.getProperty("events").getString(),
                    mapper.getTypeFactory().constructCollectionType(List.class, Event.class));
        }//from  w ww.ja v a 2s  .  c o m
    }
    return ok(render(scriptTemplate, "script", script, "workspace", workspace, "events", events,
            "eventFormatter", EVENT_FORMATTER));
}

From source file:com.youtube.processor.YoutubeTypeConverter.java

@Override
public void prepare(Object o) {
    youtubeActivityUtil = new YoutubeActivityUtil();
    mapper = StreamsJacksonMapper.getInstance();

    SimpleModule simpleModule = new SimpleModule();
    simpleModule.addDeserializer(Video.class, new YoutubeVideoDeserializer());
    mapper.registerModule(simpleModule);
    simpleModule = new SimpleModule();
    simpleModule.addDeserializer(Channel.class, new YoutubeChannelDeserializer());
    mapper.registerModule(simpleModule);
}

From source file:org.nuxeo.apidoc.snapshot.DistributionSnapshot.java

public static ObjectMapper jsonMapper() {
    final ObjectMapper mapper = new ObjectMapper().registerModule(
            new SimpleModule().addAbstractTypeMapping(DistributionSnapshot.class, RuntimeSnapshot.class)
                    .addAbstractTypeMapping(BundleInfo.class, BundleInfoImpl.class)
                    .addAbstractTypeMapping(BundleGroup.class, BundleGroupImpl.class)
                    .addAbstractTypeMapping(ComponentInfo.class, ComponentInfoImpl.class)
                    .addAbstractTypeMapping(ExtensionInfo.class, ExtensionInfoImpl.class)
                    .addAbstractTypeMapping(OperationInfo.class, OperationInfoImpl.class)
                    .addAbstractTypeMapping(SeamComponentInfo.class, SeamComponentInfoImpl.class)
                    .addAbstractTypeMapping(ServiceInfo.class, ServiceInfoImpl.class)
                    .addAbstractTypeMapping(DocumentationItem.class, ResourceDocumentationItem.class));
    mapper.addMixIn(OperationDocumentation.Param.class, OperationDocParamMixin.class);
    return mapper;
}

From source file:org.thelq.stackexchange.api.StackClient.java

public StackClient(String seApiKey) {
    Preconditions.checkNotNull(seApiKey);
    this.seApiKey = seApiKey;
    this.jsonMapper = new ObjectMapper();
    jsonMapper.registerModule(new JodaModule());
    jsonMapper.registerModule(new GuavaModule());
    jsonMapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
    jsonMapper.registerModule(new SimpleModule() {
        @Override/*from   w  w w .j  a  v  a2 s .c  o  m*/
        @SuppressWarnings("unchecked")
        public void setupModule(SetupContext context) {
            super.setupModule(context);
            context.addDeserializers(new Deserializers.Base() {
                @Override
                public JsonDeserializer<?> findEnumDeserializer(Class<?> type, DeserializationConfig config,
                        BeanDescription beanDesc) throws JsonMappingException {
                    return new UppercaseEnumDeserializer((Class<Enum<?>>) type);
                }
            });
        }
    });
}

From source file:org.apache.streams.youtube.processor.YoutubeTypeConverter.java

@Override
public void prepare(Object configurationObject) {
    mapper = StreamsJacksonMapper.getInstance();

    SimpleModule simpleModule = new SimpleModule();
    simpleModule.addDeserializer(Video.class, new YoutubeVideoDeserializer());
    mapper.registerModule(simpleModule);
    simpleModule = new SimpleModule();
    simpleModule.addDeserializer(Channel.class, new YoutubeChannelDeserializer());
    mapper.registerModule(simpleModule);
}

From source file:com.heliosapm.tsdblite.json.JSON.java

/**
 * Registers a deser for the passed class
 * @param clazz The class for which a deser is being registered
 * @param deser The deserializer//  w w w. ja  v a 2 s.  c  o  m
 */
public static <T> void registerDeserializer(final Class<T> clazz, final JsonDeserializer<T> deser) {
    if (clazz == null)
        throw new IllegalArgumentException("The passed class was null");
    if (deser == null)
        throw new IllegalArgumentException("The passed deserializer for [" + clazz.getName() + "] was null");
    final SimpleModule module = new SimpleModule();
    module.addDeserializer(clazz, deser);
    jsonMapper.registerModule(module);
}

From source file:de.fraunhofer.iosb.ilt.sta.serialize.EntityFormatter.java

public EntityFormatter(List<Property> selectedProperties) {
    mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    mapper.setPropertyNamingStrategy(new EntitySetCamelCaseNamingStrategy());
    mapper.addMixIn(Datastream.class, DatastreamMixIn.class);
    mapper.addMixIn(MultiDatastream.class, MultiDatastreamMixIn.class);
    mapper.addMixIn(FeatureOfInterest.class, FeatureOfInterestMixIn.class);
    mapper.addMixIn(HistoricalLocation.class, HistoricalLocationMixIn.class);
    mapper.addMixIn(Location.class, LocationMixIn.class);
    mapper.addMixIn(Observation.class, ObservationMixIn.class);
    mapper.addMixIn(ObservedProperty.class, ObservedPropertyMixIn.class);
    mapper.addMixIn(Sensor.class, SensorMixIn.class);
    mapper.addMixIn(Thing.class, ThingMixIn.class);
    mapper.addMixIn(UnitOfMeasurement.class, UnitOfMeasurementMixIn.class);
    mapper.addMixIn(EntitySetResult.class, EntitySetResultMixIn.class);

    SimpleModule module = new SimpleModule();
    CustomSerializationManager.getInstance().registerSerializer("application/vnd.geo+json",
            new GeoJsonSerializer());
    if (selectedProperties != null && !selectedProperties.isEmpty()) {
        module.addSerializer(Entity.class, new EntitySerializer(
                selectedProperties.stream().map(x -> x.getName()).collect(Collectors.toList())));
    } else {//from   w ww.  ja v a 2s .  c o m
        module.addSerializer(Entity.class, new EntitySerializer());
    }
    module.addSerializer(EntitySetResult.class, new EntitySetResultSerializer());
    module.addSerializer(DataArrayValue.class, new DataArrayValueSerializer());
    module.addSerializer(DataArrayResult.class, new DataArrayResultSerializer());
    mapper.registerModule(module);
}