• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

How do set custom deserializer for the class is stored in an external jar in java?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
0


I added a jar file(my other project) to my project.

Know I Create custom deserializer for a class is stored in an external jar.

I need to do something for spring to use this deserializer automatically. for example when I use this class in a Model.

when the model is loaded(get by id) from the database I want my deserializer working but I don't know how. @JsonDeserialize is not working because the class is in the jar file.

this is my class in jar file:



This is my model class:



my deserializer :



when I use the repository for getting the model I need jarFileClassDeserializer deserializer jarFileClass using Automatically. how?
 
Bartender
Posts: 653
14
TypeScript Fedora
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add getters and setters with annontations that target a 'jarFileClass' member variable.
 
meisam sabzi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Al Hobbs wrote:Add getters and setters with annontations that target a 'jarFileClass' member variable.


@Data doing that
I just forgot to add it here
how we can set custom deserializer for a class from jar library
 
Al Hobbs
Bartender
Posts: 653
14
TypeScript Fedora
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
are you getting an error?
 
Marshal
Posts: 77245
371
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't edit an old post like that; post the changes in a new post. I am refusing the edits.
 
meisam sabzi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Al Hobbs wrote:are you getting an error?


It works without error but not used a deserializer

I should add this (@JsonDeserialize(using = CustomDeSerializer.class)) for jarFileClass  but I can't because jarFileClass  is in jar but
deserializer is in my project and I can't set it
 
Saloon Keeper
Posts: 26547
187
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand all that, but I would like to make a few observations.

First "Serializable" is not JSON as such. If a class implements java.io.Serializable it's essentially promising that it can be serialized with JVM's internal binary serializer. Which is not JSON or even any plain text format.

Secondly, annotations generally are not the last word in configuration. Just because a class has been annotated with a particular property doesn't mean that it's permanently stuck with that property.

I cannot speak for your JSON framework offhand, but let's take a common annotation:


By default, the servlet class containing this annotation will dispatch URLs in the general form of "http://host/context/acccount" to that servlet.

But before there were servlet annotaions there was the WBE-INF/web.xml configuration file.  The web.xml file is still supported, and if you create it with an XML element that provides a different annotation-defined URL resource path, the web.xml definition will override the annotation on the class. As a result, you can use classes in different configurations without having to edit the class source code.

This concept is common in Java. JavaServer Faces does this, the Spring Framework does this, lots of systems do this. It's a very powerful convention.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic