Java Code Examples for com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer#createInstance()
The following examples show how to use
com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer#createInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSONPath.java From uavstack with Apache License 2.0 | 4 votes |
public boolean set(Object rootObject, Object value, boolean p) { if (rootObject == null) { return false; } init(); Object currentObject = rootObject; Object parentObject = null; for (int i = 0; i < segments.length; ++i) { // if (i == segments.length - 1) { // parentObject = currentObject; // break; // } // parentObject = currentObject; Segement segment = segments[i]; currentObject = segment.eval(this, rootObject, currentObject); if (currentObject == null) { Segement nextSegement = null; if (i < segments.length - 1) { nextSegement = segments[i + 1]; } Object newObj = null; if (nextSegement instanceof PropertySegement) { JavaBeanDeserializer beanDeserializer = null; Class<?> fieldClass = null; if (segment instanceof PropertySegement) { String propertyName = ((PropertySegement) segment).propertyName; Class<?> parentClass = parentObject.getClass(); JavaBeanDeserializer parentBeanDeserializer = getJavaBeanDeserializer(parentClass); if (parentBeanDeserializer != null) { FieldDeserializer fieldDeserializer = parentBeanDeserializer.getFieldDeserializer(propertyName); fieldClass = fieldDeserializer.fieldInfo.fieldClass; beanDeserializer = getJavaBeanDeserializer(fieldClass); } } if (beanDeserializer != null) { if (beanDeserializer.beanInfo.defaultConstructor != null) { newObj = beanDeserializer.createInstance(null, fieldClass); } else { return false; } } else { newObj = new JSONObject(); } } else if (nextSegement instanceof ArrayAccessSegement) { newObj = new JSONArray(); } if (newObj != null) { if (segment instanceof PropertySegement) { PropertySegement propSegement = (PropertySegement) segment; propSegement.setValue(this, parentObject, newObj); currentObject = newObj; continue; } else if (segment instanceof ArrayAccessSegement) { ArrayAccessSegement arrayAccessSegement = (ArrayAccessSegement) segment; arrayAccessSegement.setValue(this, parentObject, newObj); currentObject = newObj; continue; } } break; } } if (parentObject == null) { return false; } Segement lastSegement = segments[segments.length - 1]; if (lastSegement instanceof PropertySegement) { PropertySegement propertySegement = (PropertySegement) lastSegement; propertySegement.setValue(this, parentObject, value); return true; } if (lastSegement instanceof ArrayAccessSegement) { return ((ArrayAccessSegement) lastSegement).setValue(this, parentObject, value); } throw new UnsupportedOperationException(); }
Example 2
Source File: JSONPath_s.java From coming with MIT License | 4 votes |
public boolean set(Object rootObject, Object value, boolean p) { if (rootObject == null) { return false; } init(); Object currentObject = rootObject; Object parentObject = null; for (int i = 0; i < segments.length; ++i) { // if (i == segments.length - 1) { // parentObject = currentObject; // break; // } // parentObject = currentObject; Segment segment = segments[i]; currentObject = segment.eval(this, rootObject, currentObject); if (currentObject == null) { Segment nextSegment = null; if (i < segments.length - 1) { nextSegment = segments[i + 1]; } Object newObj = null; if (nextSegment instanceof PropertySegment) { JavaBeanDeserializer beanDeserializer = null; Class<?> fieldClass = null; if (segment instanceof PropertySegment) { String propertyName = ((PropertySegment) segment).propertyName; Class<?> parentClass = parentObject.getClass(); JavaBeanDeserializer parentBeanDeserializer = getJavaBeanDeserializer(parentClass); if (parentBeanDeserializer != null) { FieldDeserializer fieldDeserializer = parentBeanDeserializer.getFieldDeserializer(propertyName); fieldClass = fieldDeserializer.fieldInfo.fieldClass; beanDeserializer = getJavaBeanDeserializer(fieldClass); } } if (beanDeserializer != null) { if (beanDeserializer.beanInfo.defaultConstructor != null) { newObj = beanDeserializer.createInstance(null, fieldClass); } else { return false; } } else { newObj = new JSONObject(); } } else if (nextSegment instanceof ArrayAccessSegment) { newObj = new JSONArray(); } if (newObj != null) { if (segment instanceof PropertySegment) { PropertySegment propSegement = (PropertySegment) segment; propSegement.setValue(this, parentObject, newObj); currentObject = newObj; continue; } else if (segment instanceof ArrayAccessSegment) { ArrayAccessSegment arrayAccessSegement = (ArrayAccessSegment) segment; arrayAccessSegement.setValue(this, parentObject, newObj); currentObject = newObj; continue; } } break; } } if (parentObject == null) { return false; } Segment lastSegment = segments[segments.length - 1]; if (lastSegment instanceof PropertySegment) { PropertySegment propertySegment = (PropertySegment) lastSegment; propertySegment.setValue(this, parentObject, value); return true; } if (lastSegment instanceof ArrayAccessSegment) { return ((ArrayAccessSegment) lastSegment).setValue(this, parentObject, value); } throw new UnsupportedOperationException(); }
Example 3
Source File: JSONPath_t.java From coming with MIT License | 4 votes |
public boolean set(Object rootObject, Object value, boolean p) { if (rootObject == null) { return false; } init(); Object currentObject = rootObject; Object parentObject = null; for (int i = 0; i < segments.length; ++i) { // if (i == segments.length - 1) { // parentObject = currentObject; // break; // } // parentObject = currentObject; Segment segment = segments[i]; currentObject = segment.eval(this, rootObject, currentObject); if (currentObject == null) { Segment nextSegment = null; if (i < segments.length - 1) { nextSegment = segments[i + 1]; } Object newObj = null; if (nextSegment instanceof PropertySegment) { JavaBeanDeserializer beanDeserializer = null; Class<?> fieldClass = null; if (segment instanceof PropertySegment) { String propertyName = ((PropertySegment) segment).propertyName; Class<?> parentClass = parentObject.getClass(); JavaBeanDeserializer parentBeanDeserializer = getJavaBeanDeserializer(parentClass); if (parentBeanDeserializer != null) { FieldDeserializer fieldDeserializer = parentBeanDeserializer.getFieldDeserializer(propertyName); fieldClass = fieldDeserializer.fieldInfo.fieldClass; beanDeserializer = getJavaBeanDeserializer(fieldClass); } } if (beanDeserializer != null) { if (beanDeserializer.beanInfo.defaultConstructor != null) { newObj = beanDeserializer.createInstance(null, fieldClass); } else { return false; } } else { newObj = new JSONObject(); } } else if (nextSegment instanceof ArrayAccessSegment) { newObj = new JSONArray(); } if (newObj != null) { if (segment instanceof PropertySegment) { PropertySegment propSegement = (PropertySegment) segment; propSegement.setValue(this, parentObject, newObj); currentObject = newObj; continue; } else if (segment instanceof ArrayAccessSegment) { ArrayAccessSegment arrayAccessSegement = (ArrayAccessSegment) segment; arrayAccessSegement.setValue(this, parentObject, newObj); currentObject = newObj; continue; } } break; } } if (parentObject == null) { return false; } Segment lastSegment = segments[segments.length - 1]; if (lastSegment instanceof PropertySegment) { PropertySegment propertySegment = (PropertySegment) lastSegment; propertySegment.setValue(this, parentObject, value); return true; } if (lastSegment instanceof ArrayAccessSegment) { return ((ArrayAccessSegment) lastSegment).setValue(this, parentObject, value); } throw new UnsupportedOperationException(); }