com.ebmwebsourcing.easycommons.json.Json2XmlConverter Maven / Gradle / Ivy
The newest version!
/**
* Copyright (c) 2019-2023 Linagora
*
* This program/library is free software: you can redistribute it and/or modify
* it under the terms of the New BSD License (3-clause license).
*
* This program/library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the New BSD License (3-clause license)
* for more details.
*
* You should have received a copy of the New BSD License (3-clause license)
* along with this program/library; If not, see http://directory.fsf.org/wiki/License:BSD_3Clause/
* for the New BSD License (3-clause license).
*/
package com.ebmwebsourcing.easycommons.json;
import java.util.Optional;
import javax.xml.namespace.QName;
import de.odysseus.staxon.json.JsonXMLConfig;
import de.odysseus.staxon.json.JsonXMLConfigBuilder;
public class Json2XmlConverter {
private Json2XmlConverter() {
// Utility class --> No constructor
}
// TODO: Move here the JSON --> XML converter extracted from Petals BC REST
/**
* Create the JSON 2 XML transformation configuration
*/
public static JsonXMLConfig buildConfiguration(final QName virtRoot, final Optional multiplePi,
final Optional autoArray, final Optional autoPrimitive,
final Optional prettyPrint, final Optional namespaceDeclarations) {
final JsonXMLConfigBuilder config = new JsonXMLConfigBuilder();
if (virtRoot != null) {
config.virtualRoot(virtRoot);
}
if (multiplePi.isPresent()) {
config.multiplePI(multiplePi.get());
} else {
config.multiplePI(true);
}
if (autoArray.isPresent()) {
config.autoArray(autoArray.get());
} else {
config.autoArray(false);
}
if (autoPrimitive.isPresent()) {
config.autoPrimitive(autoPrimitive.get());
} else {
config.autoPrimitive(false);
}
if (prettyPrint.isPresent()) {
config.prettyPrint(prettyPrint.get());
} else {
config.prettyPrint(false);
}
if (namespaceDeclarations.isPresent()) {
config.namespaceDeclarations(namespaceDeclarations.get());
} else {
config.namespaceDeclarations(false);
}
return config.build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy