cancel
Showing results for 
Search instead for 
Did you mean: 

Serialization in Java ?

Srdjan
Product and Topic Expert
Product and Topic Expert
0 Kudos

Are there libraries in Java that could be used for serialization of binary data (variables, objests, ...) into XML ? Is it fast and generic, as ABAP id transformation ?

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

there is a standard built-in way to serialize objects in java to a binary format - just implement the serializable interface. That could be used for example for storing/loading objects/variable in the file system. Here is more info :

http://java.sun.com/j2se/1.5.0/docs/guide/serialization/index.html

However if you are looking for mapping objects to XML, there is something standard called "Java Architecture for XML Binding" or JAXB for short. The latest version of JAXB (2.0 I think) is provided in the latest released SAP NetWeaver server as part of Java EE 5 - here are some links :

sun home page for jaxb : http://java.sun.com/webservices/jaxb/

SAP support for JEE 5 and hence JAXB 2.0

https://www.sdn.sap.com/irj/sdn?rid=/webcontent/uuid/f0ca515c-0e01-0010-c9ba-a414ecf5432c">jee [original link is broken] [original link is broken]

HTH

Peter

Srdjan
Product and Topic Expert
Product and Topic Expert
0 Kudos

Thanks. I am not coming from Java world, so could you please clarify what is meant with "mapping objects to XML" ? I need a functionality that can take a reference to arbitrary binary variable (object, structure, ...) as input, and produce XML representation of that object as output (and vice versa). JAXB can do exactly that ?

Former Member
0 Kudos

Hi,

I am not an expert on this one, but I hope some thoughts/comments could be helpful.

The typical use of the XML is to serve as exchange format between two systems or modules - for example you are transferring data according to some schema from java to a .NET application.

So the JAXB will hide the mapping for you and generate a java object out of the schema. So you invoke only pure java code and do not bother with the XML, parsing, validation,etc.

The earlier JAXB-s used schema as input and generated an object only. Judging by your posts, you already have the objects and want to achieve some XML presentation. That is possible with the latest JAXB - 2.0, that I have told you already.

However to do so you must put "hints" for the framework as annotations (something like comments the field declaration ) in your object what exactly should go as property, what as tag, etc.

I.e. you will have to put something like :

@XmlAttribute

String myField;

If that is not what you are looking for, you could make your object serializable by implementing the interface (check the first posting), and then manually create the XML with DOM/SAX and achieve a very basic XML of the format

<MyObject mySerializedBinaryStream="01010008889ffff"/>

There as well many open third party libarires, a simple google search of "java object to XML" would give you a lot, but I would go for the standards if I were you.

HTH

Peter