arnaudroger / SimpleFlatMapper

Fast and Easy mapping from database and csv to POJO. A java micro ORM, lightweight alternative to iBatis and Hibernate. Fast Csv Parser and Csv Mapper
http://simpleflatmapper.org
MIT License
435 stars 76 forks source link

@JsonUnwrapped for SFM or map columns to inner object #708

Open Yuri-Harel opened 4 years ago

Yuri-Harel commented 4 years ago

I have a case where a stored procedure written by bad people returns 40 fields. I would like to map these fields to a more complex type. An example for the feautre I'm looking for : If I get a ResultSet with fields : id, street, city, I would like the following to map correctly :

class Result {
   String id;
  @SfmUnwrapped
   Address address;
}

class Address {
   String street;
    String city;
}

I reference @JsonUnwrapped since this is how Jackson does it for JSON. If there is another way, please advice. I know I can just add an alias for each field, but that is a bit obtuse for the reader of the code.

arnaudroger commented 4 years ago

There is a new feature that can enable by calling enableSpeculativePropertyLookupOnObject() on the Mapper factory that will enable speculative lookup on object

https://simpleflatmapper.org/2019/11/14/v8.2.1.html

so the field street should in your case endup in address.street

could you try that on the last version 8.2.1?