jasminb / jsonapi-converter

JSONAPI-Converter is a Java/Android library that provides support for working with JSONAPI spec
Apache License 2.0
272 stars 81 forks source link

@Type serialization #242

Closed InnocentRoot closed 3 years ago

InnocentRoot commented 3 years ago

Hi, thank you for this library.

It is possible to use jsonapi-converter to serialize a Type to JSON?

Example

From:

public class Gear {
  @Id
  private String id;

  @JsonProperty("tooth-count")
  private Long toothCount;
  @JsonProperty("tooth-depth")
  private Long toothDepth;
}

To:

{
    "data": [
        {
            "id": "1",
            "type": "gears",
            "attributes": {
                "tooth-count": 13,
                "tooth-depth": 21
            }
        }
    ]
}
jasminb commented 3 years ago

Hello,

Once you have ResourceConverter instance you can do:

String json = new String(converter.writeDocument(documentHoldingYourGearInstance), StandardCharsets.UTF_8);
InnocentRoot commented 3 years ago

It works,

Thanks