Class BeanDescriptor<T>

  • Type Parameters:
    T - type that this BeanDescriptor can serialize and deserialize.
    All Implemented Interfaces:
    Converter<T>, Deserializer<T>, Serializer<T>

    public class BeanDescriptor<T>
    extends Object
    implements Converter<T>
    BeanDescriptors are used to serialize/deserialize objects based on their fields, methods and constructors. By default it is supposed to work on JavaBeans, however it can be configured and extended to support different kind of objects.

    In most cases BeanDescriptors should not be used directly as it is used internally to support objects not handled by the default Converters. The most frequent case when you will use directly a BeanDescriptor is when you want to deserialize into an existing instance. Here is an example :

     Genson genson = new Genson();
     BeanDescriptorProvider provider = genson.getBeanDescriptorProvider();
     BeanDescriptor<MyClass> descriptor = provider.provide(MyClass.class, genson);
    
     MyClass existingInstance = descriptor.deserialize(existingInstance, new JsonReader("{}"),
                    new Context(genson));
     
    Author:
    Eugen Cepoi
    See Also:
    BeanDescriptorProvider
    • Method Detail

      • isReadable

        public boolean isReadable()
      • isWritable

        public boolean isWritable()
      • serialize

        public void serialize​(T obj,
                              ObjectWriter writer,
                              Context ctx)
        Specified by:
        serialize in interface Converter<T>
        Specified by:
        serialize in interface Serializer<T>
        Parameters:
        obj - we want to serialize. The object is of type T or a subclass (if this serializer has been registered for subclasses).
        writer - to use to write data to the output stream.
        ctx - the current context.
      • getOfClass

        public Class<T> getOfClass()