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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:14:21+00:00 2026-06-14T05:14:21+00:00

I have Pojo object, with getAsJson function to return Json string for this object.

  • 0

I have Pojo object, with getAsJson function to return Json string for this object.
I use JsonProperty to define json properties in this object.
Use writeValueAsString of ObjectMapper to write json string for this object.

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

@JsonIgnoreProperties(ignoreUnknown=true)
public class LogLikeArticleDetail extends BaseObject {
    private static final long serialVersionUID = -2018373118257019033L;
    @JsonProperty("LikeArticleGUId")
    private String likeArticleGUId;
    @JsonProperty("UserId")
    private String userID;
    @JsonProperty("UserName")
    private String userName;
    @JsonProperty("IP") 
    private String ip;
    @JsonProperty("OS") 
    private String os;
    @JsonProperty("UserAgent") 
    private String userAgent;
    @JsonProperty("WebsiteCode") 
    private String websiteCode;
    @JsonProperty("ArticleId") 
    private String articleID;
    @JsonProperty("ATitle") 
    private String aTitle;
    @JsonProperty("CateAlias") 
    private String cateAlias;
    @JsonProperty("LikeStatus") 
    private String likeStatus;
    @JsonProperty("TimeStamp") 
    private Date timeStamp;
        //get, set....
        //....
        @JsonIgnore
    public String getAsJSON() throws JsonGenerationException, JsonMappingException,    IOException{
        ObjectMapper mapper = new ObjectMapper();
        return mapper.writeValueAsString(this) ; 
    }
}

Now, i get result

public static void main(String[] args) throws JsonGenerationException, JsonMappingException, IOException {
        Calendar calendar =  Calendar.getInstance();
        LogLikeArticleDetail logLikeArticle = new LogLikeArticleDetail("1","2","3","4","5","6","7","8","what thing \"nothing\" show","10","11",calendar.getTime());
        System.out.println(logLikeArticle.getAsJSON());
    }

But the result’s duplicated properties:

{"LikeArticleGUId":"1","UserId":"2","UserName":"3","IP":"4","OS":"5","UserAgent":"6","WebsiteCode":"7","ArticleId":"8","ATitle":"what thing \"nothing\" show","CateAlias":"10","LikeStatus":"11","TimeStamp":1352256727062,"_likeArticleGUId":"1","websiteCode":"7","likeStatus":"11","userID":"2","userName":"3","ip":"4","os":"5","userAgent":"6","articleID":"8","aTitle":"what thing \"nothing\" show","cateAlias":"10","timeStamp":1352256727062}

Show me what’s occur in this problem ?

  • 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-14T05:14:22+00:00Added an answer on June 14, 2026 at 5:14 am

    So i do follow:
    how to specify jackson to only use fields – preferably globally

    I add

    @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
    

    before

    public class LogLikeArticleDetail extends BaseObject
    

    and the result that i want.

    So can another solve that in getAsJson() function like:

    ObjectMapper mapper  = new ObjectMapper();
    mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker()
                    .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
                    .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
                    .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
                    .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
    return mapper.writeValueAsString(this) ;
    

    Thanks for @Sean Carpenter ‘s question and @kmb385 answer in link above.

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

Sidebar

Related Questions

I have a webservice which return this kind of json object : { dossiers:
I have a DSL Java object, i.e. a POJO which returns this in setters
I have developed below which makes the use of comparator.. this my pojo.. class
I have the following POJO class for a JSON object: public class JSONChangeSet {
I have simple POJO say User Object; public class User{ private String userid; private
Reading some articles, it is best to have POJO object to do JSON or
So we use Hibernate for Object-relational mapping and we have a Student.java (POJO) and
have written this little class, which generates a UUID every time an object of
I have a json object that is actually an arraylist of objects previously converted
Given this scenario where you have transfer objects (POJO's with just getters/setters) which are

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.