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

net.minidev.json.writer.MapperRemapped Maven / Gradle / Ivy

Go to download

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

There is a newer version: 2.5.1
Show newest version
package net.minidev.json.writer;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

import net.minidev.json.parser.ParseException;

/**
 * Simple solution to supporr on read filed renaming
 * 
 * @author uriel
 *
 * @param 
 */
public class MapperRemapped extends JsonReaderI {
	private Map rename;
	private JsonReaderI parent;

	public MapperRemapped(JsonReaderI parent) {
		super(parent.base);
		this.parent = parent;
		this.rename = new HashMap();
	}

	public void renameField(String source, String dest) {
		rename.put(source, dest);
	}

	private String rename(String key) {
		String k2 = rename.get(key);
		if (k2 != null)
			return k2;
		return key;
	}

	@Override
	public void setValue(Object current, String key, Object value) throws ParseException, IOException {
		key = rename(key);
		parent.setValue(current, key, value);
	}

	public Object getValue(Object current, String key) {
		key = rename(key);
		return parent.getValue(current, key);
	}

	@Override
	public Type getType(String key) {
		key = rename(key);
		return parent.getType(key);
	}

	@Override
	public JsonReaderI startArray(String key) throws ParseException, IOException {
		key = rename(key);
		return parent.startArray(key);
	}

	@Override
	public JsonReaderI startObject(String key) throws ParseException, IOException {
		key = rename(key);
		return parent.startObject(key);
	}

	@Override
	public Object createObject() {
		return parent.createObject();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy