Posts

Showing posts from February, 2012

Eclipse Tips

Image
Escape string while pasting in the editor
Go to Window > Preferences, type escape in the search field. Go to Java > Editor > Typing preference page. In last group label "String literals" select the "Escape text when pasting into a string literal".


CXF JSON Generation remove @ prefix

Working with CXF-RS if you want to generate the json response along with xml than it becomes pain in cases where your xml is a mixture of attributes and elements. Problem comes because of default jettison json provider which is configured in cxf-rs. The jettison appends the '@' prefix  with the attributes. However, I needed json free from any prefixes. To achieve this i had configure jackson as json provider like this:


CXF-RS: Java Code Generation from xml/xsd

Cleaner approach is to use xjc like this:



Continue to dirty approach below if u need to:

When working with CXF-RS services often we start with XML message that will be served. After that we go through endless iteration of generating the right Java POJO's for the XML. The library like apache XMLBeans generate the Java code but the code generated is not what a developer would write and generally tedious to modify and understand.

I have come across a work around for generating Java classes from XSD (xml) which is very close to what a developer with decent experience will write. 
Follow the steps given below to explore the solution: 1. Generate the wsdl from from xsd as given in at this link (http://cxf.apache.org/docs/xsd-to-wsdl.html). 2. The Java classes can be generated from wsdl from maven plugin entry below find complete details herehttp://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html
org.apache.cxfcxf-codegen-plugin${cxf.version}generate-sourcesgenerate-sources…