Package java.io

Examples of java.io.ObjectStreamField


                writer.startNode(ELEMENT_DEFAULT);
                for (final String name : fields.keySet()) {
                    if (!mapper.shouldSerializeMember(currentType, name)) {
                        continue;
                    }
                    final ObjectStreamField field = objectStreamClass.getField(name);
                    final Object value = fields.get(name);
                    if (field == null) {
                        throw new ObjectAccessException("Class "
                            + value.getClass().getName()
                            + " may not write a field named '"
                            + name
                            + "'");
                    }
                    if (value != null) {
                        ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(source
                            .getClass(), name), value.getClass());
                        if (field.getType() != value.getClass() && !field.getType().isPrimitive()) {
                            final String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS);
                            if (attributeName != null) {
                                writer.addAttribute(attributeName, mapper.serializedClass(value.getClass()));
                            }
                        }
                        context.convertAnother(value);
                        writer.endNode();
                    }
                }
                writer.endNode();
            }

            @Override
            public void defaultWriteObject() {
                boolean writtenDefaultFields = false;

                final Class<?> currentType = currentTypeRef[0];
                final ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType);
                if (objectStreamClass == null) {
                    return;
                }

                for (final ObjectStreamField field : objectStreamClass.getFields()) {
                    final Object value = readField(field, currentType, source);
                    if (value != null) {
                        if (!writtenClassWrapper[0]) {
                            writer.startNode(mapper.serializedClass(currentType));
                            writtenClassWrapper[0] = true;
                        }
                        if (!writtenDefaultFields) {
                            writer.startNode(ELEMENT_DEFAULT);
                            writtenDefaultFields = true;
                        }
                        if (!mapper.shouldSerializeMember(currentType, field.getName())) {
                            continue;
                        }

                        final Class<?> actualType = value.getClass();
                        ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(source
                            .getClass(), field.getName()), actualType);
                        final Class<?> defaultType = mapper.defaultImplementationOf(field.getType());
                        if (!actualType.equals(defaultType)) {
                            final String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS);
                            if (attributeName != null) {
                                writer.addAttribute(attributeName, mapper.serializedClass(actualType));
                            }
View Full Code Here


                            final String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper);
                            Class<?> type;
                            if (classAttribute != null) {
                                type = mapper.realClass(classAttribute);
                            } else {
                                final ObjectStreamField field = objectStreamClass.getField(name);
                                if (field == null) {
                                    throw new MissingFieldException(currentType[0].getName(), name);
                                }
                                type = field.getType();
                            }
                            final Object value = context.convertAnother(result, type);
                            fields.put(name, value);
                        }
                        reader.moveUp();
View Full Code Here

        if (checked.containsKey(objVals[i]))
        {
          continue;
        }

        ObjectStreamField fieldDesc = fields[numPrimFields + i];
        Field field;
        try
        {
          field = (Field)GET_FIELD_METHOD.invoke(fieldDesc, null);
        }
View Full Code Here

                        } else {
                            _fields = new FieldDescriptor[serial_persistent_fields.length];

                            for (int i = 0; i < serial_persistent_fields.length; i++) {
                                ObjectStreamField f = serial_persistent_fields[i];

                                FieldDescriptor fd = null;

                                try {
                                    java.lang.reflect.Field rf = type
                                            .getField(f.getName());
                                    rf.setAccessible(true);

                                    if (rf.getType() == f.getType()) {
                                        fd = FieldDescriptor.get(rf);
                                    }
                                } catch (SecurityException ex) {
                                } catch (NoSuchFieldException ex) {
                                }
View Full Code Here

        // Regression for HARMONY-2674
        ObjectStreamClass objectStreamClass = ObjectStreamClass
                .lookup(File.class);
        ObjectStreamField[] objectStreamFields = objectStreamClass.getFields();
        assertEquals(1, objectStreamFields.length);
        ObjectStreamField objectStreamField = objectStreamFields[0];
        assertEquals("path", objectStreamField.getName());
        assertEquals(String.class, objectStreamField.getType());
    }
View Full Code Here

        if (checked.containsKey(objVals[i]))
        {
          continue;
        }

        ObjectStreamField fieldDesc = fields[numPrimFields + i];
        Field field;
        try
        {
          field = (Field)GET_FIELD_METHOD.invoke(fieldDesc, null);
        }
View Full Code Here

                for (Iterator iterator = fields.keySet().iterator(); iterator.hasNext();) {
                    String name = (String) iterator.next();
                    if (!mapper.shouldSerializeMember(currentType[0], name)) {
                        continue;
                    }
                    ObjectStreamField field = objectStreamClass.getField(name);
                    Object value = fields.get(name);
                    if (field == null) {
                        throw new ObjectAccessException("Class " + value.getClass().getName()
                                + " may not write a field named '" + name + "'");
                    }
                    if (value != null) {
                        ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(source.getClass(), name), field.getType());
                        if (field.getType() != value.getClass() && !field.getType().isPrimitive()) {
                            String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS);
                            if (attributeName != null) {
                                writer.addAttribute(attributeName, mapper.serializedClass(value.getClass()));
                            }
                        }
                        context.convertAnother(value);
                        writer.endNode();
                    }
                }
                writer.endNode();
            }

            public void defaultWriteObject() {
                boolean writtenDefaultFields = false;

                ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType[0]);

                if (objectStreamClass == null) {
                    return;
                }

                ObjectStreamField[] fields = objectStreamClass.getFields();
                for (int i = 0; i < fields.length; i++) {
                    ObjectStreamField field = fields[i];
                    Object value = readField(field, currentType[0], source);
                    if (value != null) {
                        if (!writtenClassWrapper[0]) {
                            writer.startNode(mapper.serializedClass(currentType[0]));
                            writtenClassWrapper[0] = true;
                        }
                        if (!writtenDefaultFields) {
                            writer.startNode(ELEMENT_DEFAULT);
                            writtenDefaultFields = true;
                        }
                        if (!mapper.shouldSerializeMember(currentType[0], field.getName())) {
                            continue;
                        }

                        ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(source.getClass(), field.getName()), field.getType());

                        Class actualType = value.getClass();
                        Class defaultType = mapper.defaultImplementationOf(field.getType());
                        if (!actualType.equals(defaultType)) {
                            String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS);
                            if (attributeName != null) {
                                writer.addAttribute(attributeName, mapper.serializedClass(actualType));
                            }
View Full Code Here

                String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper);
                            Class type;
                            if (classAttribute != null) {
                                type = mapper.realClass(classAttribute);
                            } else {
                                ObjectStreamField field = objectStreamClass.getField(name);
                                if (field == null) {
                                    throw new ObjectAccessException("Class " + currentType[0]
                                            + " does not contain a field named '" + name + "'");
                                }
                                type = field.getType();
                            }
                            Object value = context.convertAnother(result, type);
                            fields.put(name, value);
                        }
                        reader.moveUp();
View Full Code Here

        if (checked.containsKey(objVals[i]))
        {
          continue;
        }

        ObjectStreamField fieldDesc = fields[numPrimFields + i];
        Field field;
        try
        {
          field = (Field)GET_FIELD_METHOD.invoke(fieldDesc, (Object[])null);
        }
View Full Code Here

        // Regression for HARMONY-2674
        ObjectStreamClass objectStreamClass = ObjectStreamClass
                .lookup(File.class);
        ObjectStreamField[] objectStreamFields = objectStreamClass.getFields();
        assertEquals(1, objectStreamFields.length);
        ObjectStreamField objectStreamField = objectStreamFields[0];
        assertEquals("path", objectStreamField.getName());
        assertEquals(String.class, objectStreamField.getType());
    }
View Full Code Here

TOP

Related Classes of java.io.ObjectStreamField

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.