Package cc.plural.jsonij.reflect

Examples of cc.plural.jsonij.reflect.Inspection


//        }



        // Find an object inspector
        Inspection inspection = ReflectType.getInspection(objectClass);

        HashMap<String, Value> valueCollector = new HashMap<String, Value>();
        List<ClassProperty> properties = inspection.getProperties();
        Value value;
        int propCount = 0;
        for (ClassProperty property : properties) {
//            if(property.isCollector()) {
//                continue;
//            }
            ClassPropertyAccessor accessor = property.getAccessor();
            if (accessor == null || !accessor.canAccess()) {
                continue;
            }

            if (accessor.fieldType()) {
                try {
                    Field field = property.getAccessor().getField();
                    value = marshalObjectFieldValue(field, o, cycleDetector);
                    if (value == null) {
                        continue;
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                    value = new JSON.String(ex.toString());
                }
            } else if (accessor.methodType()) {
                try {
                    Method method = property.getAccessor().getMethod();
                    value = marshalObjectMethodValue(method, o, cycleDetector);
                    if (value == null) {
                        continue;
                    }
                } catch (Exception ex) {
                    value = new JSON.String(ex.toString());
                }
            } else {
                value = JSON.NULL;
            }
            propCount++;
            valueCollector.put(property.getPropertyName(), value);
        }
        if (inspection.hasInnerList()) {
            if (JSONMarshaler.ALWAYS_USE_INNER_PROPERTY || propCount > 0) {
                valueCollector.put(JSONMarshaler.INNER_ARRAY_PROPERTY, marshaler.marshalJavaList(o, cycleDetector));
            } else {
                return marshaler.marshalJavaList(o, cycleDetector);
            }
        }
        if (inspection.hasInnerMap()) {
            if (JSONMarshaler.ALWAYS_USE_INNER_PROPERTY || propCount > 0) {
                valueCollector.put(JSONMarshaler.INNER_OBJECT_PROPERTY, marshaler.marshalJavaMap(o, cycleDetector));
            } else {
                return marshaler.marshalJavaMap(o, cycleDetector);
            }
        }
        if (valueCollector.isEmpty()) {
            return null;
        } else {
            JSON.Object<JSON.String, Value> marshaledObject = new JSON.Object<JSON.String, Value>();
            Iterator<String> keySetIterator = valueCollector.keySet().iterator();
            while (keySetIterator.hasNext()) {
                String key = keySetIterator.next();
                marshaledObject.put(new JSON.String(key), valueCollector.get(key));
            }
            if (inspection.hasCollectors()) {
                for(ClassProperty collector: inspection.getCollectors()){
                    //collector.getMutator().fire(o, valueCollector);
                }
            }
            return marshaledObject;
        }
View Full Code Here


                Logger.getLogger(JSONDocumentMarshaler.class.getName()).log(Level.SEVERE, null, ex);
                throw new JSONMarshalerException("illegalAccess");
            }

            ReflectType type = ReflectType.inspectObjectType(objectClass);
            Inspection inspection = ReflectType.getInspection(objectClass);

            boolean hasCollector = inspection.hasCollectors();
            Map<CharSequence, Value> collector = null;
            Map<CharSequence, Value> innerObjectCollector = null;
            List<Value> innerArrayCollector = null;

            if (hasCollector) {
                collector = new HashMap<CharSequence, Value>();
            }
            if (inspection.hasInnerMap()) {
                innerObjectCollector = new HashMap<CharSequence, Value>();
            }
            if (inspection.hasInnerList()) {
                innerArrayCollector = new ArrayList<Value>();
            }

            for (Entry<CharSequence, Value> documentPropertyEntry : jsonObject.entrySet()) {
                CharSequence key = documentPropertyEntry.getKey();
                if (inspection.hasProperty(key.toString())) {
                    ClassProperty inspectorProperty = inspection.getProperty(key.toString());
                    Value documentValue = documentPropertyEntry.getValue();
                    try {
                        marshalJSONValue(documentValue, object, inspectorProperty);
                    } catch (IllegalAccessException ex) {
                        Logger.getLogger(JSONDocumentMarshaler.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (IllegalArgumentException ex) {
                        Logger.getLogger(JSONDocumentMarshaler.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (InvocationTargetException ex) {
                        Logger.getLogger(JSONDocumentMarshaler.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else {
                    if (hasCollector) {
                        collector.put(key, documentPropertyEntry.getValue());
                    }
                    if (inspection.hasInnerMap()) {
                        innerObjectCollector.put(key, documentPropertyEntry.getValue());
                    }
                    if (inspection.hasInnerList()) {
                        innerArrayCollector.add(documentPropertyEntry.getValue());
                    }
                }
            }

            if (hasCollector) {
                for (ClassProperty collectorProperty : inspection.getCollectors()) {
                    try {
                        collectorProperty.getMutator().fire(object, collector);
                    } catch (IllegalAccessException ex) {
                        Logger.getLogger(JSONDocumentMarshaler.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (IllegalArgumentException ex) {
                        Logger.getLogger(JSONDocumentMarshaler.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (InvocationTargetException ex) {
                        Logger.getLogger(JSONDocumentMarshaler.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
            if (inspection.hasInnerMap()) {
            }
            if (inspection.hasInnerList()) {
            }
        }
        return object;
    }
View Full Code Here

        }



        // Find an object inspector
        Inspection inspection = ReflectType.getInspection(objectClass);

        HashMap<String, Value> valueCollector = new HashMap<String, Value>();
        List<ClassProperty> properties = inspection.getProperties();
        Value value;
        int propCount = 0;
        for (ClassProperty property : properties) {
//            if(property.isCollector()) {
//                continue;
//            }
            ClassPropertyAccessor accessor = property.getAccessor();
            if (accessor == null || !accessor.canAccess()) {
                continue;
            }

            if (accessor.fieldType()) {
                try {
                    Field field = property.getAccessor().getField();
                    value = marshalObjectFieldValue(field, o, cycleDetector);
                    if (value == null) {
                        continue;
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                    value = new JSON.String(ex.toString());
                }
            } else if (accessor.methodType()) {
                try {
                    Method method = property.getAccessor().getMethod();
                    value = marshalObjectMethodValue(method, o, cycleDetector);
                    if (value == null) {
                        continue;
                    }
                } catch (Exception ex) {
                    value = new JSON.String(ex.toString());
                }
            } else {
                value = JSON.NULL;
            }
            propCount++;
            valueCollector.put(property.getPropertyName(), value);
        }
        if (inspection.hasInnerList()) {
            if (JSONMarshaler.ALWAYS_USE_INNER_PROPERTY || propCount > 0) {
                valueCollector.put(JSONMarshaler.INNER_ARRAY_PROPERTY, marshaler.marshalJavaList(o, cycleDetector));
            } else {
                return marshaler.marshalJavaList(o, cycleDetector);
            }
        }
        if (inspection.hasInnerMap()) {
            if (JSONMarshaler.ALWAYS_USE_INNER_PROPERTY || propCount > 0) {
                valueCollector.put(JSONMarshaler.INNER_OBJECT_PROPERTY, marshaler.marshalJavaMap(o, cycleDetector));
            } else {
                return marshaler.marshalJavaMap(o, cycleDetector);
            }
        }
        if (valueCollector.isEmpty()) {
            return null;
        } else {
            JSON.Object<JSON.String, Value> marshaledObject = new JSON.Object<JSON.String, Value>();
            Iterator<String> keySetIterator = valueCollector.keySet().iterator();
            while (keySetIterator.hasNext()) {
                String key = keySetIterator.next();
                marshaledObject.put(new JSON.String(key), valueCollector.get(key));
            }
            if (inspection.hasCollectors()) {
                for(ClassProperty collector: inspection.getCollectors()){
                    //collector.getMutator().fire(o, valueCollector);
                }
            }
            return marshaledObject;
        }
View Full Code Here

TOP

Related Classes of cc.plural.jsonij.reflect.Inspection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.