Partial bean serialization and deserialization + merge

I am developing a RESTful web service.

I have a bunch of entity classes (mostly JPA entities, but also other beans).

There are gazillions of object mapping, serialization, binding, and some kind of library. I am looking for one that will allow me:

  • Serialize objects in XML and JSON

    Serialization MUST be supported using getters , not just object fields.

    He MUST support submissions . By concept, I mean a way to specify a subset of the properties of an object that should be serialized. For example, see Getting partial resources at Yahoo! API social platform. I also do not want him to come back infinitely deep:

    The presentation must define the properties a) that must be exposed in the entity, and b) the representation for each of them (if they themselves are entities).

    For example, an object Personmay have representations fulland simple. When querying views simplefor Person, only properties can be serialized id, firstNameand lastName. When you request a view, the fullproperties motherand father(which themselves Persons) will also be serialized, but only with the view simple(therefore, it will not return to grandparents).

    JSON "" , Javascript. , , , -, XML Infoset.

    XML null, XML Schema xsi:nil="true".

    , , , :

    • Undefined friends ( ):

      <person>
      </person>
      
    • , :

      <person>
          <friends></friends>
      </person>
      
  • XML JSON

    . :

    ( , ).

    , .

    . Java, undefined null/empty ( Javascript/JSON, XML, , PHP,...).

    XML:

    <person>
        <lastName>Bon Jovi</lastName>
        <friends></friends>
    </person>
    

    Person, :

    person.setLastName("Bon Jovi");
    person.setFriends(new ArrayList());
    

    firstName / father, .

    , . id, , .

    / , ​​ DTO: a null "unset" " ".

, . "", : , (= , ).

+3
2

, , , , , - :

  • XML JSON bean :

  • : ( JSON XML) , . XMLDecoder bean XML ( , XMLEncoder). , , "null", XML. .

  • JSON XML , .

    • , , (, - )
    • , , , , ( , , , )
    • XML: SAX- xml - , , . SAX , , . XML pull , , ,
    • JSON: JSON . JSON , , . , ANTLR ( ), JSON , .
+1

Jackson :

ObjectMapper mapper = new ObjectMapper();
Bean existing = ...;
mapper.updatingReader(existing).readValue(jsonSource);

( JSON, ).

XML JAXB, , .

+1

Source: https://habr.com/ru/post/1706145/


All Articles