Git Product home page Git Product logo

Comments (3)

antoniosanct avatar antoniosanct commented on August 11, 2024

@Aravinda93

  1. The correct name of the property is "org.glassfish.jaxb.namespacePrefixMapper".
  2. This property is exclusive for marshalling. You can not use at unmarshalling process.

Regards,
Antonio.

from jaxb-ri.

Aravinda93 avatar Aravinda93 commented on August 11, 2024

@antoniosanct Thanks a lot for the response. For your convience I have added the sample code repo here: https://github.com/Aravinda93/test/tree/main

I was trying couple of things thats the reason I added the org.glassfish.jaxb.runtime.marshaller.NamespacePrefixMapper but I have tried the org.glassfish.jaxb.namespacePrefixMapper and that did not work either for me.

As you mentioned I have removed the Unmarshaller part although I was not using it and kept only the Marshaller but still I get the same error:

Exception in thread "main" jakarta.xml.bind.JAXBException: property "org.glassfish.jaxb.namespacePrefixMapper" is not supported

Following is my main class updated:

import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.Marshaller;

import java.util.HashMap;
import java.util.Map;

public class MainXML {
    public static void main(String[] args) throws Exception {
        final Map<String, String> myNamespaces = new HashMap<>();
        myNamespaces.put("test", "https://test.com");
        myNamespaces.put("test2", "https://test2.com");

        final JAXBContext jaxbContext = JAXBContext.newInstance("io.test.convert", Thread.currentThread().getContextClassLoader(),
                new HashMap<>() {
                    {
                        put(
                                "org.glassfish.jaxb.namespacePrefixMapper",
                                new CustomNamespacePrefixMapper());
                    }
                });
        //final JAXBContext jaxbContext = JAXBContext.newInstance("io.test.convert", Thread.currentThread().getContextClassLoader());

        final Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
        marshaller.setProperty("org.glassfish.jaxb.namespacePrefixMapper", new CustomNamespacePrefixMapper());

        final Child1 child1 = new Child1();
        child1.setName("Batman");
        child1.setAge("30");
        child1.setType("Superhero");
        child1.setOriginalName("Bruce Wayne");

        marshaller.marshal(child1, System.out);
    }
}

from jaxb-ri.

antoniosanct avatar antoniosanct commented on August 11, 2024

@Aravinda93
You can not set this property at context initialization. See constants defined here to check what properties you can initialize. Lines 23 and 28 of your class are correct (delete hashmap initialization in 15 and uncomment 23 to run fine).

Regards,
Antonio.

from jaxb-ri.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.