ENI (4) Fastexml compatibility issues

0. Introduction

Fasterxml is very easy to use for managing XML, but there are some issues that are not compatible with JAXB. Here are some examples of how to solve this handicaps

1. @XmlElementRef, @XmlMixed ...

Here is an example of the generated KeyInfoType class


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
public class KeyInfoType {

    @XmlElementRefs({
        @XmlElementRef(name = "KeyName", namespace = "http://www.w3.org/2000/09/xmldsig#", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "KeyValue", namespace = "http://www.w3.org/2000/09/xmldsig#", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "RetrievalMethod", namespace = "http://www.w3.org/2000/09/xmldsig#", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "X509Data", namespace = "http://www.w3.org/2000/09/xmldsig#", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "PGPData", namespace = "http://www.w3.org/2000/09/xmldsig#", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "SPKIData", namespace = "http://www.w3.org/2000/09/xmldsig#", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "MgmtData", namespace = "http://www.w3.org/2000/09/xmldsig#", type = JAXBElement.class, required = false)
    })
    @XmlMixed
    @XmlAnyElement(lax = true)
    protected List<Object> content;


The possible solution is changing @XmlElementRef by @XmlElement

The proposal is:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class KeyInfoEduType {
        //Begin substitution
 @XmlElement(name = "KeyName", namespace = "http://www.w3.org/2000/09/xmldsig#", type = JAXBElement.class, required = false)
 @Getter @Setter
 protected String keyName;
 
 @XmlElement(name = "KeyValue", namespace = "http://www.w3.org/2000/09/xmldsig#", type = JAXBElement.class, required = false)
 @Getter @Setter
 protected KeyValueEduType keyValue; 
 
 @XmlElement(name = "RetrievalMethod", namespace = "http://www.w3.org/2000/09/xmldsig#", type = JAXBElement.class, required = false)
 @Getter @Setter
 protected RetrievalMethodType retrievalMethod; 
 
 @XmlElement(name = "X509Data", namespace = "http://www.w3.org/2000/09/xmldsig#", type = JAXBElement.class, required = false)
 @Getter @Setter
 protected X509DataEduType x509Data; 
 
 @XmlElement(name = "PGPData", namespace = "http://www.w3.org/2000/09/xmldsig#", type = JAXBElement.class, required = false)
 @Getter @Setter
 protected PGPDataType pGPData; 
 
 @XmlElement(name = "SPKIData", namespace = "http://www.w3.org/2000/09/xmldsig#", type = JAXBElement.class, required = false)
 @Getter @Setter
 protected SPKIDataType sPKIData; 
 
 @XmlElement(name = "MgmtData", namespace = "http://www.w3.org/2000/09/xmldsig#", type = JAXBElement.class, required = false)
 @Getter @Setter
 protected String mgmtData; 
 //End substitution
 
 

Note that I am using Lombok for avoiding Getters and Setters.
It is more verbose... but seems to work

But this transformation must affect all classes that use the @XmlElementRef annotation

2. Special class ObjtectType


In schemas, it is recommended to use STRONGLY typed elements... But this class is used against this principle.

The designer of the schema, has made this class a "jumble" (the Spanish of "cajón de sastre"?) for storing any type of objects.

After manually analysing some examples of ENI documents, a more typed class is proposed.

The initial class partial code is:


1
2
3
4
5
6
public class ObjectType {

    @XmlMixed
    @XmlAnyElement(lax = true)
    protected List<Object> content;
 

and the proposal is:


1
2
3
4
5
6
7
8
9
public class ObjectEduType {

    @XmlValue
    @Getter @Setter
    protected byte[] content;
 
    @XmlElement(name = "QualifyingProperties", namespace = "http://uri.etsi.org/01903/v1.3.2/#")
    @Getter @Setter
    protected QualifyingPropertiesEduType qualifyingProperties;


3. The loss of namespaces prefixes in attributes affected by @XmlElement


There are many attributes annotated by @XmlElement, that do not have namespaces prefixes when are serialized to XML.


A possible and verbose solution is to add the "namespace" attribute to the annotation.
NOTE: This CANNOT be done in the @Attribute annotation!!

Here is the RSAKeyValueType class before these changes:


1
2
3
4
5
6
public class RSAKeyValueType {

    @XmlElement(name = "Modulus", required = true)
    protected byte[] modulus;
    @XmlElement(name = "Exponent", required = true)
    protected byte[] exponent;


and after the addition of "namespace":


1
2
3
4
5
6
public class RSAKeyValueEduType {

 @XmlElement(name = "Modulus", namespace = "http://www.w3.org/2000/09/xmldsig#", required = true)
 protected byte[] modulus;
 @XmlElement(name = "Exponent", namespace = "http://www.w3.org/2000/09/xmldsig#", required = true)
 protected byte[] exponent;

4. Conclusion

This is a tedious job,  but if you make these changes to all the affected classes, you can have your project enabled for "fasterxml".

Comments

Popular posts from this blog

ORVE WS (Dynamic) (4) Jackson XML mapper

ENI (1) ENI Document OR the Spanish Electronic Administration Mafia

ORVE WS (Dynamic) (12) Defiining the control tables