net.minidev.json.mapper.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.
package net.minidev.json.mapper;
import java.io.IOException;
import java.lang.reflect.Type;
import net.minidev.json.parser.ParseException;
public class UpdaterMapper extends AMapper {
final T obj;
final AMapper> mapper;
public UpdaterMapper(T obj) {
if (obj == null)
throw new NullPointerException("can not update null Object");
this.obj = obj;
this.mapper = (AMapper>) Mapper.getMapper(obj.getClass());
}
public UpdaterMapper(T obj, Type type) {
if (obj == null)
throw new NullPointerException("can not update null Object");
this.obj = obj;
this.mapper = (AMapper>) Mapper.getMapper(type);
}
/**
* called when json-smart parser meet an object key
*/
public AMapper> startObject(String key) throws ParseException, IOException {
Object bean = mapper.getValue(obj, key);
if (bean == null)
return mapper.startObject(key);
return new UpdaterMapper