0

I've been trying to convert XML file to java objects efficiently but I haven't succeeded yet. I have seen JAXB notation, and a few others but they havent looked efficient to me and I need to use json. I need help with efficient code example.

5
  • 1
    Good to hear that you have attempted this. What have you tried? Commented Aug 27, 2012 at 11:54
  • 1
    Use JAXB is the better option to proceed further for marshalling and unmarshalling in java Commented Aug 27, 2012 at 11:54
  • You could have at the very least provided an XML snippet you're trying to convert and the corresponding java class. Commented Aug 27, 2012 at 11:56
  • i tried unmarshalling by using JAXB but i had an exception about resource finding. it means i locate the xml file to wrong place. i located it webcontent in eclipse project but resuorce can't be found Commented Aug 27, 2012 at 12:05
  • I handled the problem. Thanks a lot to that tries t help. I used JAXB and with a little difference; importing the other version of the same named libray. thanks Commented Aug 27, 2012 at 12:48

1 Answer 1

2

Do not invent the wheel. These libraries (GSON, Jackson...) are pretty fast, tested and have huge community. If it was easy to write things better, it would have been already done.

And this is not really a question ;-)

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

7 Comments

i tried unmarshalling by using JAXB but i had an exception about resource finding. it means i locate the xml file to wrong place. i located it webcontent in eclipse project but resuorce can't be found
update your question (exception, file hierarchy etc.). From your current post it is really hard to guess what went wrong and what you expect.
JAXBContext context1 = JAXBContext.newInstance(JavaObject.class);final Unmarshaller unmarshaller = context1.createUnmarshaller(); File file = new File("sample-xml.xml"); final JavaObject object = (JavaObject) unmarshaller.unmarshal(new FileInputStream(file));
in this case, i get file not found exception
and where is the file, if in src directory, tham 1) make sure, that you have maven resources polugin configured 2) you should load it using classloader.getResource(). Also file has method getAbsolutePath, so printout the path and make sure, that the file is there.
|

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.