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

com.cognitect.transit.impl.JsonVerboseEmitter Maven / Gradle / Ivy

Go to download

Transit is a data format and a set of libraries for conveying values between applications written in different languages. This library provides support for marshalling Transit data to/from Java.

There is a newer version: 1.0.371
Show newest version
// Copyright (c) Cognitect, Inc.
// All rights reserved.

package com.cognitect.transit.impl;

import com.cognitect.transit.WriteHandler;
import com.fasterxml.jackson.core.JsonGenerator;

import java.util.Map;
import java.util.function.Function;

public class JsonVerboseEmitter extends JsonEmitter {

    @Deprecated
    public JsonVerboseEmitter(JsonGenerator gen, WriteHandlerMap writeHandlerMap) {
        super(gen, writeHandlerMap, null);
    }

    public JsonVerboseEmitter(JsonGenerator gen, WriteHandlerMap writeHandlerMap, WriteHandler defaultWriteHandler) {
        super(gen, writeHandlerMap, defaultWriteHandler);
    }

    public JsonVerboseEmitter(JsonGenerator gen, WriteHandlerMap writeHandlerMap, WriteHandler defaultWriteHandler, Function transform) {
        super(gen, writeHandlerMap, defaultWriteHandler, transform);
    }

    @Override
    public void emitString(String prefix, String tag, String s, boolean asMapKey, WriteCache cache) throws Exception {
        String outString = cache.cacheWrite(Util.maybePrefix(prefix, tag, s), asMapKey);
        if(asMapKey)
            gen.writeFieldName(outString);
        else
            gen.writeString(outString);
    }

    @Override
    protected void emitTagged(String t, Object o, boolean ignored, WriteCache cache) throws Exception {
        emitMapStart(1L);
        emitString(Constants.ESC_TAG, t, "", true, cache);
        marshal(o, false, cache);
        emitMapEnd();
    }

    @Override
    protected void emitMap(Iterable> i, boolean ignored, WriteCache cache) throws Exception {

        long sz = Util.mapSize(i);

        emitMapStart(sz);
        for (Map.Entry e : i) {
            marshal(e.getKey(), true, cache);
            marshal(e.getValue(), false, cache);
        }
        emitMapEnd();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy