net.minidev.json.writer.UpdaterMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-smart Show documentation
Show all versions of json-smart Show documentation
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.
The newest version!
package net.minidev.json.writer;
import java.io.IOException;
import java.lang.reflect.Type;
import net.minidev.json.parser.ParseException;
public class UpdaterMapper extends JsonReaderI {
final T obj;
final JsonReaderI> mapper;
public UpdaterMapper(JsonReader base, T obj) {
super(base);
if (obj == null)
throw new NullPointerException("can not update null Object");
this.obj = obj;
this.mapper = (JsonReaderI>) base.getMapper(obj.getClass());
}
public UpdaterMapper(JsonReader base, T obj, Type type) {
super(base);
if (obj == null)
throw new NullPointerException("can not update null Object");
this.obj = obj;
this.mapper = (JsonReaderI>) base.getMapper(type);
}
/**
* called when json-smart parser meet an object key
*/
public JsonReaderI> startObject(String key) throws ParseException, IOException {
Object bean = mapper.getValue(obj, key);
if (bean == null)
return mapper.startObject(key);
return new UpdaterMapper