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 6563329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:49:06+00:00 2026-05-25T13:49:06+00:00

Apologies in advance. This seems like a simple task, but hours later on Google

  • 0

Apologies in advance. This seems like a simple task, but hours later on Google and with guess/check, I still can’t figure it out.

I’m writing a Java convenience wrapper library for an API my company provides. One of the classes looks something like this:

class View extends Model<View>
{
    List<Column> columns;
    Column primaryColumn;
}

However, our API actually wants a primaryColumnId integer, not an actual Column object. I want to maintain the strongly-typed getPrimaryColumn() and setPrimaryColumn(Column) in the library to reduce developer error, but I’m having significant difficulty writing some sort of translation between the getter/setter that we need to ser/deser to/from JSON.

I’m using the standard Bean serialization strategy. I’d like to avoid the wholly-custom approach because in reality View has dozens of fields. Here’s what I’ve figured out so far.

I think (haven’t tested yet) that I can handle the serialization case simply by creating a custom JsonSerializer that looks something like:

public static class ColumnIdSerializer extends JsonSerializer<Column>
    {
        @Override
        public void serialize(Column column, JsonGenerator jsonGenerator,
                              SerializerProvider serializerProvider) throws IOException {
            jsonGenerator.writeFieldName("primaryColumnId");
            jsonGenerator.writeNumber(column.id);
        }
    }

And then assigning the annotation to the appropriate place:

@JsonSerialize(using = Column.ColumnIdSerializer.class)
public Column getPrimaryColumn() { /* ... */ }

This allows me to serialize the id rather than the whole class, and rename the key from primaryColumn to primaryColumnId.

Now, we get to deserialization. Here I run into three problems.

The first is that in order to successfully deserialize the column from the id, we have to first have the list of columns. This is solvable using @JsonPropertyOrder on the class. Great, that’s done.

The second is that I need to tell Jackson to look under primaryColumnId rather than primaryColumn for the value. I don’t know how to do this; the JsonDeserializer appears to kick in after the key has already been found, so it’s too late to modify it. JsonSchema looks like it might be relevant but I can’t find any documentation or internet chatter on how to use it.

The third is that from the custom JsonDeserializer class I’ll have to be able to reference the View that’s being deserialized in order to ask it for a Column in return for my id int. There doesn’t appear to be a way to do that.

Should I just cave and add a public getPrimaryColumnId() and setPrimaryColumnId(Integer), or is there a way to overcome these obstacles?

  • 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-05-25T13:49:07+00:00Added an answer on May 25, 2026 at 1:49 pm

    Turns out that since Jackson does nasty reflection, it can see through private methods. So, the trick ended up simply being along the lines of:

    private void setPrimaryColumnId(Integer id) {...}
    
    private Integer getPrimaryColumnId() {...}
    
    public void setPrimaryColumn(Column column) {...}
    
    @JsonIgnore
    public Column getPrimaryColumn() {...}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies in advance if this is obvious, but I can't seem to find an
This seems like a simple question to ask but, is it generally a good
Apologies in advance if this is a silly question but I'm wondering which might
Okay, so first, I have searched for this everywhere but it seems like every
I apologize in advance if this question seems remedial. Which would be considered more
I apologize in advance if this question seems confused. The behaviour I am seeing
I'm not so savvy with MYSQL, so my apologies in advance is this is
Greetings, Apologies in advance that I have not researched this toughly enough to answer
This may be a bit of an abstract question, so apologies in advance. I
This, I'm sure is a pretty basic question about JavaScript, so apologies in advance.

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.