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

cn.allbs.hj212.ser.StringMapSegmentSerializer Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package cn.allbs.hj212.ser;

import cn.allbs.hj212.config.SegmentGenerator;
import cn.allbs.hj212.exception.SegmentFormatException;

import java.io.IOException;
import java.util.Map;

/**
 * 功能:
 *
 * @author chenQi
 */
public class StringMapSegmentSerializer
        implements SegmentSerializer> {

    @Override
    public void serialize(SegmentGenerator generator, Map data) throws IOException, SegmentFormatException {
        if (generator.nextToken() == null) {
            generator.initToken();
        }
        writeMap(generator, data);
    }

    private void writeMap(SegmentGenerator generator, Map result) throws IOException, SegmentFormatException {
        for (Map.Entry kv : result.entrySet()) {
            generator.writeKey(kv.getKey());
            generator.writeValue(kv.getValue());
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy