0

In my xsd-file I offer different date formats for the type appointment:

<xs:complexType name="appointment">
  <xs:choice>
    <xs:element name="jahr.Monat.Tag.Zeit" minOccurs="0" type="xs:dateTime"/>
    <xs:element name="jahr.Monat.Tag" minOccurs="0" type="xs:date"/>
    <xs:element name="jahr.Monat" minOccurs="0" type="xs:gYearMonth"/>
    <xs:element name="jahr" minOccurs="0" type="xs:gYear"/>
  </xs:choice>
</xs:complexType>

This json-object:

{
  "AppointmentElementOfTypeappintment":
         { 
             "jahr.Monat.Tag": "2002-09-24"
          } 
} 

ends in an empty element:

<AppointmentElementOfTypeappintment/>

Only if I choose gYear I get a filled element in xml:

{
  "AppointmentElementOfTypeappintment":
         { 
             "jahr": "2002"
          } 
}

results in:

<AppointmentElementOfTypeappintment><jahr>2002</jahr></AppointmentElementOfTypeappintment>

My mapping object is as following:

...,
 {
    localName: 'appointment',
    propertyInfos: [{
        name: 'jahrMonatTagZeit',
        elementName: 'jahr.Monat.Tag.Zeit',
        typeInfo: 'DateTime'
      }, {
        name: 'jahrMonatTag',
        elementName: 'jahr.Monat.Tag',
        typeInfo: 'Date'
      }, {
        name: 'jahrMonat',
        elementName: 'jahr.Monat',
        typeInfo: 'GYearMonth'
      }, {
        name: 'jahr',
        typeInfo: 'GYear'
      }]
  }, ....
saab
  • 129
  • 1
  • 3
  • 16

1 Answers1

0

Your mapping says name:'jahrMonatTag', so try:

{
    "AppointmentElementOfTypeappintment":
    { 
        "jahrMonatTag": "2002-09-24"
    } 
}

Update

I understand the point. However the json data that I pass to the marshaller come from an external modul i.e. I have no influence on the field names. What I do in my module is to convert these jsons into xmls. Appearently the library they use ro gather data from DB producing the jsons uses the dotted form for the fields i.e. 'jahr.Monat.Tag'.

Then you have to change property names in the mapping:

{
        name: 'jahr.Monat.Tag',
        elementName: 'jahr.Monat.Tag',
        typeInfo: 'Date'
}

If you write your mapping manually, this is easy to do.

If you first write an XML Schema and the compile it into mappings then at the moment you'll be getting Java-style property names (jahrMonatTag vs. jahr.Monat.Tag). Jsonix Schema Compiler does not generate "original" property names at the moment, but that's an implementable feature. Please file an issue.

Disclaimer: I'm the author of Jsonix.

lexicore
  • 42,748
  • 17
  • 132
  • 221
  • I understand the point. However the json data that I pass to the marshaller come from an external modul i.e. I have no influence on the field names. What I do in my module is to convert these jsons into xmls. Appearently the library they use ro gather data from DB producing the jsons uses the dotted form for the fields i.e. 'jahr.Monat.Tag'. – saab Jul 15 '16 at 10:03
  • I am very new to all thes stuff (gthub etcc.). How might I pull(use) your update? – saab Jul 17 '16 at 11:02
  • OK, I have already added a new issue as you sujested. Thanks. – saab Jul 18 '16 at 08:26