• United States
IBM?
  • Site map
IBM?
  • Marketplace

  • Close
    Search
  • Sign in
    • Sign in
    • Register
  • IBM Navigation
IBM Developer Answers
  • Spaces
    • Blockchain
    • IBM Cloud platform
    • Internet of Things
    • Predictive Analytics
    • Watson
    • See all spaces
  • Tags
  • Users
  • Badges
  • FAQ
  • Help
Close

Name

Community

  • Learn
  • Develop
  • Connect

Discover IBM

  • ConnectMarketplace
  • Products
  • Services
  • Industries
  • Careers
  • Partners
  • Support
10.190.13.195

IBM Cloud platform×

Refine your search by using the following advanced search options.

Criteria Usage
Questions with keyword1 or keyword2 keyword1 keyword2
Questions with a mandatory word, e.g. keyword2 keyword1 +keyword2
Questions excluding a word, e.g. keyword2 keyword1 -keyword2
Questions with keyword(s) and a specific tag keyword1 [tag1]
Questions with keyword(s) and either of two or more specific tags keyword1 [tag1] [tag2]
To search for all posts by a user or all posts with a specific tag, start typing and choose from the suggestion list. Do not use a plus or minus sign with a tag, e.g., +[tag1].
  • Ask a question

How do I resolve a deserialization issue about Joda DateTime used by a RESTful (2.0) service in WAS Liberty?

270006UY0A gravatar image
Question by S.Baumann  (2871) | Oct 17, 2015 at 01:15 PM wasdevlibertyrestibmclouddatetimedeserialize

Hello experts,

I am currently developing a Bluemix application using a RESTful interface (jaxrs-2.0). The service is working as expected in general.

Passing simple Objects seems to work without any issues. However, I would like to use the Joda library for Date, DateTimes and Calendar functions. There is one complex object - ClassA - that should be send from the client to update. ClassA contains 2 DateTime objects of the Joda library.

I have already written the XMLJavaAdapterTyp and it is set on package level. So passing objects back from the server works just fine. The server is consuming and producing application/json & application/xml content types.

The objects are stored in a different package than the RESTService interface. A summary of the project structure can be found below:

 src
 |--packageA
 |  |--ClassA.java
 |  |  |--DateTime start
 |  |  |--DateTime end
 |  |  |-- ... other ('simple') fields ...
 |  |
 |  |--XMLJavaAdapter implementation for Joda DateTime
 |  |
 |  +--package-info
 |     +--XMLJavaApater Annotation
 |
 |--packageB
    +--RESTService
       |--...several methods
       +--@PUT public ClassA update(ClassA instanceToUpdate)
  

I am deploying the project to a local WAS Liberty profile, containing following features:

     <featureManager>
         <feature>jpa-2.1</feature>
         <feature>localConnector-1.0</feature>
         <feature>jaxrs-2.0</feature>
     </featureManager>

The server start shows additionally following message:

[AUDIT   ] CWWKF0012I: The server installed the following features: [jdbc-4.1, localConnector-1.0, json-1.0, jaxrs-2.0, jpa-2.1, servlet-3.1, jaxrsClient-2.0, jndi-1.0].

I already tested some GET methods returning ClassA and this is working fine. However, while trying the update method (@PUT) via a RESTConsole, I am receiving the following issue in the console:

 [ERROR   ] SRVE0777E: Exception thrown by application class 'org.codehaus.jackson.map.ext.JodaDeserializers.provide:32'
 java.lang.NoClassDefFoundError: org/joda/time/ReadableInstant
     at org.codehaus.jackson.map.ext.JodaDeserializers.provide(JodaDeserializers.java:32)
     at [internal classes]
 Caused by: java.lang.ClassNotFoundException: org.joda.time.ReadableInstant cannot be found by com.ibm.ws.jaxrs-2.0.common_1.0.10.cl50720150827-0437
     at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:439)
     ... 1 more

Some researches in the net showed additional information that this seems to be caused by a missing resource export: java.lang.ClassNotFoundException org.joda.time.ReadableInstant not found by jackson-mapper-asl There also seems to be a fix: Classloading / module issue with using resteasy-jackson-provider and joda classes

I have added the Joda Library (jar-file) as Library in the Java Built Path (as Library) and marked it also as Export to be sure. Moreover the jar-file is included in the WebContent/WEB-INF/lib/ directory.

Unfortunately, I do not know, where to apply the fix mentioned in the above reference. I am suspecting the WAS Liberty is missing the required reference, as the console stack trace shows com.ibm.ws.jaxrs-2.0.common_1.0.10.cl50720150827-0437 cannot find the required class. Any hint is much appreciated!

I attached the whole WAS Liberty messages.log (it is not that long) to the question so you see the full stack as well.

Does anybody know how to resolve such an issue? I already spent several hours with but I am not close to a solution I am thinking.

Thanks a lot for your inputs!

Best Regards

Steffen

messages.log (10.7 kB)

People who like this

  0   Show 2
Comment
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
270006UY0A gravatar image S.Baumann (2871)   Oct 17, 2015 at 05:12 PM 0
Share

Already adjusted the server.xml configuration as follows:

 <library id="joda" apiTypeVisibility="spec,ibm-api,api,third-party">
    <fileset dir="${server.config.dir}/lib/joda" includes="*.jar" scanInterval="0s"/>
 </library>
 <library id="jackson" apiTypeVisibility="spec,ibm-api,api,third-party">
    <fileset dir="${server.config.dir}/lib/jackson" includes="*.jar" scanInterval="0s"/>
 </library>
 ...
 <webApplication id="WebApp" location="WebApp.war" name="WebApp">
    <classloader delegation="parentFirst" privateLibraryRef="joda"></classloader>
    <classloader delegation="parentLast" privateLibraryRef="jackson"></classloader>
 </webApplication>

The ${server.config.dir}/lib/joda directory contains the Joda library. The ${server.config.dir}/lib/jackson includes the jackson-core-asl & jackson-mapper-asl(both in version 1.9.13).

Additional recommendations are highly appreciated!

270006UY0A gravatar image S.Baumann (2871)   Oct 18, 2015 at 09:45 AM 0
Share

Adding the jackson libraries to the WebContent/WEB-INF/lib as well, causes following exception:

 org.codehaus.jackson.map.ext.JodaDeserializers cannot be cast to org.codehaus.jackson.map.util.Provider

Moreover, the previously working GET mehtod to receive a ClassA object is throwing following error:

 java.lang.ClassCastException: org.codehaus.jackson.map.ext.JodaSerializers cannot be cast to org.codehaus.jackson.map.util.Provider

Summarizing it looks like the WAS Liberty profile is not working in harmony with the jackson libraries in combination with Joda

I am not whether this is counted as progress in solving the issue.

Additional hints are still much appreciated!

2 answers

  • Sort: 
270006UY0A gravatar image
Accepted answer

Answer by S.Baumann (2871) | Oct 18, 2015 at 10:34 AM

Hello all,

I finally solved the issue by using everything @Tom has provided as well as using the correct jackson library. Mistakenly, I was focused on jackson-core-asl & jackson-mapper-asl only based on the fix for JBoss cited in my questions.

After using a 'full' jackson library, the issue is gone and I am able to share the required objects. Moreover, the full library seems to be on a later release as well, which is somehow even better.


Please find below the whole working configuration that is working now:

added server libraries

 ${server.config.dir}
 |--lib
 |  |--json
 |  |  +--joda-time-2.8.2.jar
 |  |
 |  +--jackson
 |     +--jackson-all-1.9.9.jar
 |
 +--... default directories 

server.xml:

  <library id="joda" apiTypeVisibility="spec,ibm-api,api,third-party">
     <fileset dir="${server.config.dir}/lib/joda" includes="*.jar" scanInterval="0s"/>
  </library>
  <library id="jackson" apiTypeVisibility="spec,ibm-api,api,third-party">
     <fileset dir="${server.config.dir}/lib/jackson" includes="*.jar" scanInterval="0s"/>
  </library>
  ...
  <webApplication id="WebApp" location="WebApp.war" name="WebApp">
     <classloader delegation="parentFirst" privateLibraryRef="joda"></classloader>
     <classloader delegation="parentLast" privateLibraryRef="jackson"></classloader>
  </webApplication>

WebContent/WEB-INF/lib

 WebContent
 |--WEB-INF
 |  |--lib
 |  |  |--jackson-all-1.9.9.jar
 |  |  +--joda-time-2.8.2.jar
 |  |
 |  +--... default stuff like web.xml
 |
 +--META-INF (default) 

object structure (important to use XML as well as JSON)

 src
 |--packageA
 |  |--ClassA.java - annotated with @XmlRootElement
 |  |  |--DateTime start
 |  |  |--DateTime end
 |  |  +-- ... other ('simple') fields ...
 |  |
 |  |--XMLJavaAdapter implementation for Joda DateTime
 |  |
 |  +--package-info
 |     +--XMLJavaApater annotation
 |
 |--packageB
    +--RESTService (consumes & produces JSON and XML)
       |--...several methods
       |--@GET public ClassA get(String id)
       +--@PUT public ClassA update(ClassA instanceToUpdate)



Many thanks to @Tom for his excellent information to the classloader settings and API usage in WAS Liberty! Hope this helps others, too.

Best regards

Steffen


jackson-all-199jar.zip (1.0 MB)
Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
100000BRDE gravatar image

Answer by Tom Alcott (1727) | Oct 17, 2015 at 03:05 PM

The fix and resolution cited are specific to JBoss and the JBoss module.xml file (which is specific to the JBoss server implementation)

The Liberty profile analog steps are detailed here

http://www-01.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.wlp.nd.doc/ae/twlp_classloader_use_lib.html?lang=en

An additional suggested reference is

http://www-01.ibm.com/support/knowledgecenter/api/content/SSAW57_8.5.5/com.ibm.websphere.wlp.nd.doc/ae/twlp_classloader.html

Comment
S.Baumann

People who like this

  1   Show 2   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
270006UY0A gravatar image S.Baumann (2871)   Oct 17, 2015 at 04:49 PM 0
Share

Hello @Tom

thanks for your response. Some additional searches lead me to the same direction. However, I was not sure how to set it properly. Thanks for your reference, showing a great example. Unfortunately, it did not show any change.

The configuration looks as followed:

 <webApplication id="MyApp" location="MyApp.war" name="MyApp">
     <classloader delegation="parentLast">
     <privateLibrary>
       <fileset dir="${server.config.dir}/lib" includes="*.jar" scanInterval="5s" />
     </privateLibrary>
   </classloader>
 </webApplication>

The ${server.config.dir}/lib contains the same libraries as the built path does.

However, I tried to 'override' the Jackson library to use the latest one. This forced the application to throw a different exception. Key message is as follows:

 org.codehaus.jackson.map.ext.JodaDeserializers cannot be cast to org.codehaus.jackson.map.util.Provider

I got the error when I added the jackson libraries (jackson-core-asl & jackson-mapper-asl) to the WebContent/WEB-INF/lib directory

I also added the jackson libraries to the created ${server.config.dir}/lib directory - no change. Not sure whether this is progress. Do you maybe have any other idea to solve this issue?

270006UY0A gravatar image S.Baumann (2871)   Oct 18, 2015 at 09:30 AM 0
Share

Meanwhile I have reviewed the source code of the mentioned jackson classes org.codehaus.jackson.map.ext.JodaDeserializers and org.codehaus.jackson.map.util.Provider. As the JodaDeserializers is implementing the Provider interface there is not explanation to me, why there should be a ClassCastException.

GrepCode of JodaDeserializers shows the following:

 ...
 14 import org.codehaus.jackson.map.util.Provider;
 ...
 22 public class JodaDeserializers
 23     implements Provider<StdDeserializer<?>>
 24 {
 ...

Follow this question

111 people are following this question.

Answers

Answers & comments

Related questions

Using the maven cloudfoundry plugin how can I import trusted certificates? 0 Answers

Why WEB-INF\lib\*jar become a file after cf push to bluemix? 3 Answers

Oracle DB Service Plugin for Liberty Buildpack 1 Answer

Where to find Liberty features like couchdb-1.0 etc., and how to add those into my Eclipse 2 Answers

Connecting to Dashdb using a data source in the Liberty For Java Profile in Bluemix 2 Answers

  • Contact
  • Privacy
  • IBM Developer Terms of use
  • Accessibility
  • Report Abuse
  • Cookie Preferences

Powered by AnswerHub

Authentication check. Please ignore.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • API Connect
  • Analytic Hybrid Cloud Core
  • Application Performance Management
  • Appsecdev
  • BPM
  • Blockchain
  • Business Transaction Intelligence
  • CAPI
  • CAPI SNAP
  • CICS
  • Cloud Analytics
  • Cloud Automation
  • Cloud Object Storage
  • Cloud marketplace
  • Collaboration
  • Content Services (ECM)
  • Continuous Testing
  • Courses
  • Customer Experience Analytics
  • DB2 LUW
  • DataPower
  • Decision Optimization
  • DevOps Services
  • Developers IBM MX
  • Digital Commerce
  • Digital Experience
  • Finance
  • Global Entrepreneur Program
  • Hadoop
  • Hybrid Cloud Core
  • IBM Cloud platform
  • IBM Design
  • IBM Forms Experience Builder
  • IBM Maximo Developer
  • IBM StoredIQ
  • IBM StoredIQ-Cartridges
  • IIDR
  • ITOA
  • InformationServer
  • Integration Bus
  • Internet of Things
  • Kenexa
  • Linux on Power
  • LinuxONE
  • MDM
  • Mainframe
  • Messaging
  • Node.js
  • ODM
  • Open
  • PowerAI
  • PowerVC
  • Predictive Analytics
  • Product Insights
  • PureData for Analytics
  • Push
  • QRadar App Development
  • Run Book Automation
  • Search Insights
  • Security Core
  • Storage
  • Storage Core
  • Streamsdev
  • Supply Chain Business Network
  • Supply Chain Insights
  • Swift
  • UBX Capture
  • Universal Behavior Exchange
  • UrbanCode
  • WASdev
  • WSRR
  • Watson
  • Watson Campaign Automation
  • Watson Content Hub
  • Watson Marketing Insights
  • dW Answers Help
  • dW Premium
  • developerWorks Sandbox
  • developerWorks Team
  • Watson Health
  • More
  • Tags
  • Questions
  • Users
  • Badges