1
@XMLRootElement(name="BookStore")
@XMLJavaTypeAdapter(BookStoreAdapter.class)
public class BookStore{}

when I unmarshall xml into BookStore POJO, BookStoreAdapter.class is not invoked. and yes BookStoreAdapter.class extends XmlAdapter<String, BookStore> and implements abstract methods.

the reason I am trying this contraption is bcz I have a rest web service like this

class interface{
  @PUT
  @Consumes({"application/xml"})
  public void service(BookStore bs);
}

so without Adapter I can receive xml request and Apache CXF through JAXB would create a POJO for me from xml to BookStore, but I want both pojo and xml as I want to store xml request in DB. for this reason I was thinking I could have adapter on BookStore than in adapter's unmarshall method I would take xml String and store it in DB and Create BootStore pojo as well like following

@Override
    public BookStore unmarshal(String bookStoreXML) {
        storeXMLInDB(bookStoreXML);
        BookStore bs = null;
        try {
            bs = ((BookStore) JAXBContext.newInstance(BookStore.class);.createUnmarshaller().unmarshal(new StringReader(bookStoreXML)));
        } catch (Exception ex) {
        }
        return bs;
    }

I know its bad code, I am just learning, please help. Thanks for your time and inputs.

  • Probably best approach like [here](https://stackoverflow.com/q/11038313/592355).. ([cxf - interceptor](https://cxf.apache.org/docs/interceptors.html)!?) – xerx593 Feb 04 '22 at 11:17
  • yes, I could use this approach. Thanks. But for my knowledge what wrong I am doing in above approach, can't we us these 2 annotations together ? – Kuldeep Singh Feb 04 '22 at 13:28
  • the most obvious advantages would be: 1. no double/re-marshalling 2. using the "framework as intended/designed" 3. no side effects/experiments :) – xerx593 Feb 04 '22 at 15:21
  • got it, thanks again – Kuldeep Singh Feb 04 '22 at 21:45

0 Answers0