Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deep-merge array items in example JSONs before generating schemas #423

Closed
alperenbolat opened this issue Sep 22, 2015 · 1 comment
Closed
Milestone

Comments

@alperenbolat
Copy link

my json file is ...

{  
  "sabit": {
     "lokasyon":{
            "lat":35.35719841230264,
            "lng":18.569335341453552
         },
      "gemi":{  
         "irtifa":30,
         "yalpa":40,
         "dikeyYalpa":50,
         "pruva":60,
         "kabarma":70
      }
   },
   "arayuzler":{  
      "frekans":80,
      "secilenler":[  
         {  
            "tip":"Konsol",
            "isim":"Konsol",
            "silinemez":true
         },
         {  
            "tip":"Dosya",
            "isim":"Dosya",
            "ozellikler":{  
               "dosya":"noktalar.txt"
            },
            "silinemez":true
         },
         {  
            "isim":"ethernet1",
            "ozellikler":{  
               "ip":"192.168.1.1",
               "port":"3000",
               "protokol": "TCP"
            },
            "tip":"Ethernet",
            "id":1440658104985
         },
         {  
            "isim":"raw2",
            "ozellikler":{  
               "macAddr":"08:00:26:27:31:20"
            },
            "tip":"Raw Ethernet",
            "id":1440658326143
         },
         {  
            "isim":"seri1",
            "ozellikler":{  
               "port":"3000"
            },
            "tip":"Seri Kanal",
            "id":1440658229857
         }
      ]
   }
}

it is generate result is 'özellkler' :
public class Ozellikler {

@JsonProperty("port")
private String port;

/**
 * 
 * @return
 *     The port
 */
@JsonProperty("port")
public String getPort() {
    return port;
}

but json file is contain : port , mac address , ip , protocol , dosya
ı am not resolve this problem
I would appreciate it if you could help
thanks...

@thachhoang thachhoang changed the title Not generate all properties Deep-merge array items in example JSONs before generating schemas Aug 23, 2016
@thachhoang
Copy link
Collaborator

thachhoang commented Aug 23, 2016

A simpler example:

[
    {
        "scalar" : 99,
        "list" : [
            { "a" : 1 }
        ],
        "obj" : { "name" : "k" }
    },
    {
        "scalar" : "what",
        "list" : [
            { "b" : 1 }
        ],
        "obj" : { "index" : 8 }
    }
]

In the root array, we're ignoring the first object entirely, overwriting the keys with values from the second object.

We can merge values for the same keys, so the schema is more accurate:

[
    {
        "scalar" : "what", # pick last, because different types
        "list" : [
            # will recursive merge these
            { "a" : 1 },
            { "b" : 1 }
        ],
        "obj" : { "name" : "k", "index" : 8 }
    }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants