Skip to content

Element is not known in this context, could not determine its type, or trying to use marshaller. #192

Closed

Description

@gitowiec

Hi
I have an issue while using the marshaller. I am new to JSONIX and I would like to convert JavaScript object to XML document. I generated mapping based on Schemat_JPK_FA(1)_v1-0.xsd file (in the project).
Could You @highsource please take a look and tell me why I get "Element [JPK] is not known in this context" error?

Here is my project
https://github.com/gitowiec/jsonix-tryout

And here is sample of XML I want to get from JSON:

<?xml version="1.0" encoding="UTF-8"?>
<JPK xmlns="http://jpk.mf.gov.pl/wzor/2016/03/09/03095/" xmlns:ns2="http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2016/01/25/eD/DefinicjeTypy/">
  <Naglowek>
    <KodFormularza kodSystemowy="JPK_FA (1)" wersjaSchemy="1-0">JPK_FA</KodFormularza>
    <WariantFormularza>1</WariantFormularza>
    <CelZlozenia>1</CelZlozenia>
    <DataWytworzeniaJPK>2018-02-23T13:47:59.311+01:00</DataWytworzeniaJPK>
    <DataOd>2018-01-01</DataOd>
    <DataDo>2018-01-31</DataDo>
    <DomyslnyKodWaluty>PLN</DomyslnyKodWaluty>
    <KodUrzedu>2205</KodUrzedu>
  </Naglowek>
  <Podmiot1>
    <IdentyfikatorPodmiotu>
      <ns2:NIP>123123123</ns2:NIP>
      <ns2:PelnaNazwa>qwerty</ns2:PelnaNazwa>
      <ns2:REGON>123123</ns2:REGON>
    </IdentyfikatorPodmiotu>
    <AdresPodmiotu>
      <ns2:KodKraju>PL</ns2:KodKraju>
      <ns2:Wojewodztwo>pomorskie</ns2:Wojewodztwo>
      <ns2:Powiat>dsadasd</ns2:Powiat>
      <ns2:Gmina>dsadasd</ns2:Gmina>
      <ns2:Ulica>gfdsgdsf</ns2:Ulica>
      <ns2:NrDomu>11</ns2:NrDomu>
      <ns2:Miejscowosc>fdsfdsf</ns2:Miejscowosc>
      <ns2:KodPocztowy>44-444</ns2:KodPocztowy>
      <ns2:Poczta>dsadasdsa</ns2:Poczta>
    </AdresPodmiotu>
  </Podmiot1>
  <Faktura typ="G"> 
    <P_1>2018-01-12</P_1>
    <P_2A>FV SP / 198 / 01 / 2018</P_2A>
    <P_3A>dsadasdsadasf</P_3A>
    <P_3B>fdsfdsfdsfsdf</P_3B>
    <P_3C>fdsfdsfdsfsdfsad</P_3C>
    <P_3D>dsadsadsafgdsgsdfsdf</P_3D>
    <P_4B>4324324324</P_4B>
    <P_5B>4324324234</P_5B>
    <P_6>2018-01-10</P_6>
    <P_13_1>5316.00</P_13_1>
    <P_14_1>1222.68</P_14_1>
    <P_13_2>0.00</P_13_2>
    <P_14_2>0.00</P_14_2>
    <P_13_3>0.00</P_13_3>
    <P_14_3>0.00</P_14_3>
    <P_13_5>0.00</P_13_5>
    <P_14_5>0.00</P_14_5>
    <P_13_6>0.00</P_13_6>
    <P_13_7>0.00</P_13_7>
    <P_15>6538.68</P_15>
    <P_16>false</P_16>
    <P_17>false</P_17>
    <P_18>false</P_18>
    <P_19>false</P_19>
    <P_20>false</P_20>
    <P_21>false</P_21>
    <P_23>false</P_23>
    <P_106E_2>false</P_106E_2>
    <P_106E_3>false</P_106E_3>
    <RodzajFaktury>VAT</RodzajFaktury>
  </Faktura>
  <FakturaWiersz typ="G">
    <P_2B>FV SP / 9 / 02 / 2018</P_2B>
    <P_7>Transport - UPS</P_7>
    <P_8A>sztuk</P_8A>
    <P_8B>1</P_8B>
    <P_9A>15.37</P_9A>
    <P_11>15.37</P_11>
    <P_12>23</P_12>
  </FakturaWiersz>
  <FakturaWierszCtrl>
    <LiczbaWierszyFaktur>399</LiczbaWierszyFaktur>
    <WartoscWierszyFaktur>20383.81</WartoscWierszyFaktur>
  </FakturaWierszCtrl>
</JPK>

Activity

  1. highsource commented on May 10, 2018

    @highsource
    Owner

    I've sent you a PR with the fix:

    gitowiec/jsonix-tryout#1

    There were three problems with your code:

    • Main problem was that you use require('./mappings/JPK') as mapping, should be require('./mappings/JPK').JPK. Generated modules export mappings as a property of the mapping's name.
    • For {JPK: value} to work, your target namespace has to be associated with the empty namespace.
    • In JSON, you should use property names as generated in mappins. Like, nip instead of NIP.

    With a few fixes I could generate the following XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <JPK xmlns="http://jpk.mf.gov.pl/wzor/2016/03/09/03095/" xmlns:ns2="http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2016/01/25/eD/DefinicjeTypy/">
       <Naglowek />
       <Podmiot1>
          <IdentyfikatorPodmiotu>
             <ns2:NIP>3213213213</ns2:NIP>
             <ns2:PelnaNazwa>dsadas adas Z dsadsa dsadsad</ns2:PelnaNazwa>
             <ns2:REGON>32123213333</ns2:REGON>
          </IdentyfikatorPodmiotu>
          <AdresPodmiotu>
             <ns2:KodKraju>PL</ns2:KodKraju>
          </AdresPodmiotu>
       </Podmiot1>
       <Faktura>
          <P_1>2018-01-12</P_1>
          <P_2A>FV SP / 198 / 01 / 2018</P_2A>
          <P_3A>rewrwer erwerw-r  rew</P_3A>
          <P_3B>dsfdsfgfdh dfsfds f sdfds</P_3B>
          <P_3C>zzzzzz</P_3C>
          <P_3D>eeeee</P_3D>
          <P_4B>1232132133</P_4B>
          <P_5B>1232132133</P_5B>
          <P_6>2018-01-10</P_6>
          <P_13_1>5316</P_13_1>
          <P_14_1>1222.68</P_14_1>
          <P_13_2>0</P_13_2>
          <P_14_2>0</P_14_2>
          <P_13_3>0</P_13_3>
          <P_14_3>0</P_14_3>
          <P_13_5>0</P_13_5>
          <P_14_5>0</P_14_5>
          <P_13_6>0</P_13_6>
          <P_13_7>0</P_13_7>
          <P_15>6538.68</P_15>
          <P_16>false</P_16>
          <P_17>false</P_17>
          <P_18>false</P_18>
          <P_19>false</P_19>
          <P_20>false</P_20>
          <P_21>false</P_21>
          <P_23>false</P_23>
          <P_106E_2>false</P_106E_2>
          <P_106E_3>false</P_106E_3>
          <RodzajFaktury>VAT</RodzajFaktury>
       </Faktura>
    </JPK>
  2. added a commit that references this issue on May 10, 2018
  3. gitowiec commented on May 10, 2018

    @gitowiec
    Author

    Thank You Very Much for Your Support,
    Is it possible to pretty print XML string and make new lines after every > closing of opening tag?
    I can't find API document where I could lookup parameters of marshaller.marshalString()

  4. highsource commented on May 10, 2018

    @highsource
    Owner

    You're welcome.

    No, there are now built-in support for pretty-printing. Jsonix uses standard XMLSerializer which, as far as I know, does not support pretty-printing. Quick SO search did not produce any good results.

    If you figure this out, please let me know.

  5. self-assigned this
    on May 10, 2018
  6. added this to the milestone on May 10, 2018
  7. gitowiec commented on May 10, 2018

    @gitowiec
    Author

    I used this package to pretty print XML https://www.npmjs.com/package/xml-formatter
    And if I may ask, is there option to make marshaller.marshalString() allow using key names (localName's) beginning with UpperCase and not stripping underscore? Just make it leave property names unchanged?
    I would like this behaviour because using cxsd package I can generate TypeScript types for JSON data structure and that types have property names same as original element names (Naglowek instead of naglowek, Podmiot1 instead of podmiot1, P_2A instead of p2A, and so on)

  8. highsource commented on May 11, 2018

    @highsource
    Owner

    And if I may ask, is there option to make marshaller.marshalString() allow using key names (localName's) beginning with UpperCase and not stripping underscore?

    No, not at the moment. File a feature request if you want this.

  9. gitowiec commented on May 11, 2018

    @gitowiec
    Author

    Ok I think it's a jsonix-schema-compiler feature so I just reported feature-request there highsource/jsonix-schema-compiler#82

  10. highsource commented on May 11, 2018

    @highsource
    Owner

    Correct. Well done, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions