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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:32:27+00:00 2026-06-17T14:32:27+00:00

I’m using Spring rest with below code base: When I invoke /info by passing

  • 0

I’m using Spring rest with below code base:

When I invoke /info by passing string value in request body, I’m expecting the below response if this value is not present in my backend database.

{"output":-10} 

but instead it returns me below response:

{"id": 0, "output":-10} 

Can any one tell me how to get rid of this id default value? If there is a boolean variable in JSON mapper, then that would also get returned as

{"id": 0, "booleanVar": false, "output":-10} 

Can any one tell me how to get rid of this default value?

Controller.java

@RequestMapping(value = "heartbeat", method = RequestMethod.GET, consumes="application/json")
public ResponseEntity<String> getHeartBeat() throws Exception {
    String curr_time = myService.getCurrentTime();      
    return MyServiceUtil.getResponse(curr_time, HttpStatus.OK);
}

@RequestMapping(value = "info", method = RequestMethod.POST, consumes="application/json")
public ResponseEntity<String> getData(@RequestBody String body) throws Exception {
    ....
    myInfo = myService.getMyInfo(myServiceJson);
    return MyServiceUtil.getResponse(myInfo, responseHeader, HttpStatus.OK);
}

MyService.java

@Override
public String getCurrentTime() throws Exception {
    String currentDateTime = null;
    MyServiceJson json = new MyServiceJson();
    ObjectMapper mapper = new ObjectMapper().configure(SerializationConfig.Feature.DEFAULT_VIEW_INCLUSION, false);

    try {           
        Date currDate = new Date(System.currentTimeMillis());
        currentDateTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(currDate);           
        json.setCurrentDateTime(currentDateTime);

        ObjectWriter writer = mapper.writerWithView(Views.HeartBeatAPI.class);
        return writer.writeValueAsString(json);

    } catch (Exception e) {
        throw new Exception("Excpetion in getCurrentTime: ", HttpStatus.BAD_REQUEST);           
    }
}

@Override
public String getMyInfo(MyServiceJson myServiceJson) throws Exception {             
    MyServiceJson json = new MyServiceJson();
    json.setFirstName("hhh");
    json.setLastName("abc");

    ObjectMapper mapper = new ObjectMapper();
    return mapper.writeValueAsString(json);
}

Views.java

public class Views {
    public static class HeartBeatAPI {  }
}

MyServiceJson.java

@JsonSerialize(include = Inclusion.NON_NULL)
public class MyServiceJson {
    private int id;
    private String firstName;   
    private String lastName;

    @JsonView(Views.HeartBeatAPI.class) 
    private String currentDateTime;

    // Getter/Setter for the above variables here
    .....

}
  • 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-17T14:32:28+00:00Added an answer on June 17, 2026 at 2:32 pm

    Use Integer class instead of int primitive type. Primitive types always hold default values, where class type defaults to null.

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

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

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.