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

org.emfjson.jackson.databind.ser.EMapEntrySerializer Maven / Gradle / Ivy

There is a newer version: 1.3.0
Show newest version
/*
 * Copyright (c) 2015 Guillaume Hillairet.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Guillaume Hillairet - initial API and implementation
 *
 */
package org.emfjson.jackson.databind.ser;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

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

public class EMapEntrySerializer extends JsonSerializer {

	@Override
	public void serialize(Map.Entry entry, JsonGenerator jg, SerializerProvider serializers) throws IOException {
		if (entry.getKey() instanceof String) {
			jg.writeObjectField((String) entry.getKey(), entry.getValue());
		} else {
			jg.writeStartObject();
			jg.writeObjectField("key", entry.getKey());
			jg.writeObjectField("value", entry.getValue());
			jg.writeEndObject();
		}
	}

	@Override
	public Class handledType() {
		return Map.Entry.class;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy