spinjar.com.minidev.json.writer.UpdaterMapper Maven / Gradle / Ivy
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