Generating code by given JSON API structure

I’m not sure whether it’s related entirely to SuiteCRM or to JSON API. Presumably, something in the middle.

I have a resource called Lead whose entire structure is available by the following request:

GET {{crm_base_url}}/api/v8/modules/Leads/meta/attributes

It gives me the following response:

{
    "meta": {
        "Leads": {
            "attributes": {
                "id": {
                    "name": "id",
                    "vname": "LBL_ID",
                    "type": "id",
                    "required": true,
                    "reportable": true,
                    "comment": "Unique identifier",
                    "inline_edit": false
                },
                "first_name": {
                    "name": "first_name",
                    "vname": "LBL_FIRST_NAME",
                    "type": "varchar",
                    "len": "100",
                    "unified_search": true,
                    "full_text_search": {
                        "boost": 3
                    },
                    "comment": "First name of the contact",
                    "merge_filter": "selected"
                },
                ...

I want to use one of JSON API client library. Let it be one of Java implementation and I have to write such code as:

@JsonApiResource(type = "Leads")
public class Lead {

    @JsonApiId
    private UUID id;

    @JsonProperty("first_name")
    private String firstName;
    ...

How can I avoid the manual work and autogenerate such classes?

It doesn’t matter what programming language to use, the approach should produce a class.

Maybe there are ideas here

https://stackoverflow.com/questions/2591098/how-to-parse-json-in-java

but I don’t know much about Java to help you… like you said, this is a common problem and there are many solutions out there.

1 Like

Not really, I was thinking about generation classes by schema. Something like this: https://www.slideshare.net/amusarra/how-tobuildjavaclientforsugarcrm-enit10

Ok.

BTW, do you know that there is a sample Java client for SuiteCRM lying around somewhere on the internet (with source code)?

https://suitecrm.com/suitecrm/forum/suitecrm-7-0-discussion/5730-desktop-client