All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tinkerpop.rexster.protocol.serializer.json.templates.MetaTemplate Maven / Gradle / Ivy

There is a newer version: 2.6.0
Show newest version
package com.tinkerpop.rexster.protocol.serializer.json.templates;

import com.tinkerpop.rexster.protocol.msg.RexProMessageMeta;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.node.JsonNodeFactory;
import org.codehaus.jackson.node.ObjectNode;

import java.util.Iterator;
import java.util.Map;

/**
 * @author Blake Eggleston (bdeggleston.github.com)
 */
public class MetaTemplate implements JsonTemplate {

    @Override
    public RexProMessageMeta deserialize(JsonNode json) {
        RexProMessageMeta meta = new RexProMessageMeta();
        Iterator itr = json.getFieldNames();
        while (itr.hasNext()) {
            String key = itr.next();
            JsonNode val = json.get(key);
            meta.put(key, JsonConverter.fromJsonNode(val));
        }
        return meta;
    }

    @Override
    public JsonNode serialize(RexProMessageMeta src) {
        ObjectNode map = new ObjectNode(JsonNodeFactory.instance);
        for (Map.Entry entry: src.entrySet()) {
            map.put(entry.getKey(), JsonConverter.toJsonNode(entry.getValue()));
        }
        return map;
    }

    public static MetaTemplate instance = new MetaTemplate();
    static public MetaTemplate getInstance() {
        return instance;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy