1

I want to know if is possible to create a abstract class adress to using with job and home tags?

Like in this code

<person>
  <home>
    <adress>
      <street>marte</street>
      <number>200</number>
    </adress>
  </home>
  <job>
    <adress>
      <street>saint loius</street>
      <number>100</number>
    </adress>
  </job>
</person>

If is possible, can someome show me a example code...

4
  • Why would you want it to be abstract? Commented Sep 5, 2013 at 14:38
  • Did you try to code yourself first? Show us some code? Commented Sep 5, 2013 at 14:38
  • @SotiriosDelimanolis i thougth it was good for the code, but i can be concrete class Commented Sep 5, 2013 at 14:42
  • @NarendraPathai @XmlSeeAlso({ AdressHome.class, AdressJob.class }) public abstract class Adress { @XmlElement(name = "street") private String street; @XmlElement(name = "number") private String number; //getter and setter } @XmlRootElement(name = "home") @XmlAccessorType(XmlAccessType.FIELD) public class AdressHome extends Adress { } @XmlRootElement(name = "job") @XmlAccessorType(XmlAccessType.FIELD) public class AdressJob extends Adress { } Commented Sep 5, 2013 at 14:48

2 Answers 2

1

This can be done by leveraging the @XmlElementRef annotation on a property in which the type is the common super class. Then annotate each subclass with the @XmlRootElement annotation.

Sign up to request clarification or add additional context in comments.

Comments

0

My problem was in the interface class...

I didn´t put annotation to map the fields

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.