marcusaram / snakeyaml

Automatically exported from code.google.com/p/snakeyaml
Apache License 2.0
1 stars 0 forks source link

Allow direct field access bypassing setters and getters #55

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When doing serialization / deserialization it is often desirable to allow
direct field access. Standard Java serialization does it, Hibernate and
JaxB allow it. 

I tried to extend Constructor in version 1.6 but since most methods are
private there is not much you can do without touching the code itself.
There should by a switch to either follow JavaBeans mode or to access all
the classes' fields. 

In our setting I would like to use yaml files to write test fixtures for
our domain objects. Since these have a bit of internal state and fields
that can only be written to via setters under certain circumstance it would
be really handy to make direct field access possible. This would emulate
what hibernate does when loading an object. 

Original issue reported on code.google.com by m...@ivu.de on 8 Mar 2010 at 5:33

GoogleCodeExporter commented 9 years ago
Can you please provide an example of a Java class and the corresponding YAML 
document?

Original comment by aso...@gmail.com on 8 Mar 2010 at 11:26

GoogleCodeExporter commented 9 years ago
Thanks for changing the issue to Enhancement. I couldn't change it after 
hitting the
send button too early. 

A sample class would be:

public class SampleDomainClass {

    @Inject
    private transient Dependecy dependency;

    private Long id;    
    private String invoiceAddress;
    private Customer customer;

    public Long getId() {
        return id;
    }

    public setCustomer(Customer customer) {
        invoiceAddress = customer.getInvoiceAddress().clone();
        this.customer = customer;
    }    

    public Customer getCustomer() {
        return customer;
    }

    public String getInvoiceAddress() {
        return invoiceAddress;
    }
}

Which should be loaded from

id: 5
invoiceAddress: Old Samplestreet 452, Some Town
customer:
  invoiceAddress: New Samplestreet 123, Some Town

invoiceAddress should still have the value "Old Samplestreet 452, Some Town" 
after
deserialization. This is a pattern that re-appears in accounting where an 
invoice
must always retain the data that was send out to the receiver no matter if the
customer changes his address after the invoice was sent out. 

Original comment by m...@ivu.de on 9 Mar 2010 at 3:22

GoogleCodeExporter commented 9 years ago
I did not quite catch you. What do you expect to achieve ? Do you wish to skip
setCustomer(Customer customer)  and set fields directly to keep both addresses ?
Can you may be provide a link to see related Hibernate code ?

Original comment by aso...@gmail.com on 9 Mar 2010 at 4:08