'How to unmarshal from xml file object that has private field List<>

I have a SnefConfig.xml file. In this file I have 2 objects. One of them include lists. When I unmarshal this file, everything is correct except lists. Instead of configured values I get default values. I don't get how to unmarshall object that has private field list.

SnefConfig.xml

<?xml version="1.0"?>
<snefConfigFile>
        <nrfConfig>
             //some fields. No lists. Here everything is correct
        </nrfConfig>
        <smfManagerConfig>
                <snefSmfService>ENABLED</snefSmfService>
                <smfDirectConnection>true</smfDirectConnection>
                        <list>
                                <smfAddresses>http://some.uri</smfAddresses>
                        </list>
                <nrfSmfSearchValue></nrfSmfSearchValue>
                        <list>
                                <smfEventTriggers>PDU_SES_REL</smfEventTriggers>
                                <smfEventTriggers>PDU_SES_EST</smfEventTriggers>
                        </list>
                <map5GAttributeTo4G>true</map5GAttributeTo4G>
                <scpAddress></scpAddress>
                <smfMaxRequestAttempts>3</smfMaxRequestAttempts>
                <smpFqdn></smpFqdn>
        </smfManagerConfig>
</snefConfigFile>

How do I unmarshall:

private void loadConfig(String path) {
    SnefConfigFile tempConfig = new SnefConfigFile();
    try {
        JAXBContext context = JAXBContext.newInstance(SnefConfigFile.class);
        Unmarshaller um = context.createUnmarshaller();
        tempConfig = (SnefConfigFile) um.unmarshal(new FileReader(path));
        if (LogUtils.isDebugEnabled(thisClass)) LogUtils.debug(thisClass, "NRF configurations were loaded from " + path);
    } catch (Exception e) {
        LogUtils.warn(thisClass, "Failed to load configurations from " + path, e);
    }
    setSnefConfigFile(tempConfig);
}

SnefConfigFile is an object that stores 2 configurations (objects):

@XmlRootElement
public class SnefConfigFile {
    private static final Class<SnefConfigFile> thisClass = SnefConfigFile.class;
    private NrfConfig nrfConfig;
    private SmfManagerConfig smfManagerConfig;

    public NrfConfig getNrfConfig() {
        return nrfConfig;
    }

    @XmlElement(name="nrfConfig")
    public void setNrfConfig(NrfConfig nrfConfig) {
        this.nrfConfig = nrfConfig;
        LogUtils.info(thisClass, "nrfConfig value updated: " + this.nrfConfig);
    }

    public SmfManagerConfig getSmfManagerConfig() {
        return smfManagerConfig;
    }

    @XmlElement(name="smfManagerConfig")
    public void setSmfManagerConfig(SmfManagerConfig smfManagerConfig) {
        this.smfManagerConfig = smfManagerConfig;
        LogUtils.info(thisClass, "smfManagerConfig value updated: " + this.smfManagerConfig);
    }

    @Override
    public String toString() {
        return "SnefConfigFile [" + nrfConfig.toString() + ", " + smfManagerConfig.toString() + "]";
    }
}

The problematic SmfManagerConfig.java:

public class SmfManagerConfig {
    //default values

    private State snefSmfService = DEFAULT_SNEF_SMF_SERVICE;
    private Interceptor accessTokenObject = DEFAULT_ACCESS_TOKEN_OBJECT;
    private boolean smfDirectConnection = DEFAULT_SMF_DIRECT_CONNECTION;
    private List<String> smfAddresses = DEFAULT_SMF_ADDRESSES;
    private ArrayList<Object> nrfSmfSearchValue = DEFAULT_NRF_SMF_SEARCH_VALUE;    //TODO next stage: choose the type of the object in Nnrf_NFDiscovery_SearchNFInstances task
    private List<SmfEvent> smfEventTriggers = DEFAULT_SMF_EVENT_TRIGGERS;    //SmfEvent is enum
    private boolean map5GAttributeTo4G = DEFAULT_MAP_5G_ATTRIBUTES_TO_4G;
    private boolean accessTokenUsage = DEFAULT_ACCESS_TOKEN_USAGE;
    private String scpAddress = DEFAULT_SCP_ADDRESS;
    private int smfMaxRequestAttempts = DEFAULT_SMF_MAX_REQUEST_ATTEMPTS;
    private String smpFqdn = DEFAULT_SMP_FQDN;

    //getters and setters

    @XmlTransient    //as I understood Unmarshaller will ignore this field
    public void setAccessTokenObject(Interceptor accessTokenObject) {
        this.accessTokenObject = accessTokenObject;
    }
}

How to unmarshall these lists?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source