Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8199527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:11:12+00:00 2026-06-07T06:11:12+00:00

I am trying to write a custom JSON deserializer in Spring. I want to

  • 0

I am trying to write a custom JSON deserializer in Spring. I want to use default serializer for most part of fields and use a custom deserializer for few properties. Is it possible?
I am trying this way because, most part of properties are values, so for these I can let Jackson use default deserializer; but few properties are references, so in the custom deserializer I have to query a database for reference name and get reference value from database.

I’ll show some code if needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:11:13+00:00Added an answer on June 7, 2026 at 6:11 am

    I’ve searched a lot and the best way I’ve found so far is on this article:

    Class to serialize

    package net.sghill.example;
    
    import net.sghill.example.UserDeserializer
    import net.sghill.example.UserSerializer
    import org.codehaus.jackson.map.annotate.JsonDeserialize;
    import org.codehaus.jackson.map.annotate.JsonSerialize;
    
    @JsonDeserialize(using = UserDeserializer.class)
    public class User {
        private ObjectId id;
        private String   username;
        private String   password;
    
        public User(ObjectId id, String username, String password) {
            this.id = id;
            this.username = username;
            this.password = password;
        }
    
        public ObjectId getId()       { return id; }
        public String   getUsername() { return username; }
        public String   getPassword() { return password; }
    }
    

    Deserializer class

    package net.sghill.example;
    
    import net.sghill.example.User;
    import org.codehaus.jackson.JsonNode;
    import org.codehaus.jackson.JsonParser;
    import org.codehaus.jackson.ObjectCodec;
    import org.codehaus.jackson.map.DeserializationContext;
    import org.codehaus.jackson.map.JsonDeserializer;
    
    import java.io.IOException;
    
    public class UserDeserializer extends JsonDeserializer<User> {
    
        @Override
        public User deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
            ObjectCodec oc = jsonParser.getCodec();
            JsonNode node = oc.readTree(jsonParser);
            return new User(null, node.get("username").getTextValue(), node.get("password").getTextValue());
        }
    }
    

    Edit:
    Alternatively you can look at this article which uses new versions of com.fasterxml.jackson.databind.JsonDeserializer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a custom deserializer for Jackson and I want to make
I'm trying to write a custom servlet (for AJAX/JSON) in which I would like
I'm trying to write a custom rendering template for use in the DisplayForm of
I'm trying to write a custom MarkupExtension that allows me to use my own
I'm trying to write a custom validation for my store.website . I want the
I'm trying to write a custom JavascriptConverter for use with a WebService I'm writing.
I'm trying to write a custom maven plugin, and want to get some information
I'm trying to write a custom powershell script that will create a local user
I am trying to write a custom magento module and i've got it all
I am trying to write a custom tag. I can write attributes; however, I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.