How to return JSON data from spring Controller using @ResponseBody

后端 未结 8 1048
情深已故
情深已故 2020-11-27 04:55

Spring version 4.2.0, Hibernate 4.1.4 Here is my Controller function:

@RequestMapping(value = \"/mobile/getcomp\", method = Req         


        
相关标签:
8条回答
  • 2020-11-27 05:24

    In my case I was using jackson-databind-2.8.8.jar that is not compatible with JDK 1.6 I need to use so Spring wasn't loading this converter. I downgraded the version and it works now.

    0 讨论(0)
  • 2020-11-27 05:27

    Yes just add the setters/getters with public modifier ;)

    0 讨论(0)
  • 2020-11-27 05:29

    When I was facing this issue, I simply put just getter setter methods and my issues were resolved.

    I am using Spring boot version 2.0.

    0 讨论(0)
  • 2020-11-27 05:35

    I was using groovy+springboot and got this error.

    Adding getter/setter is enough if we are using below dependency.

    implementation 'org.springframework.boot:spring-boot-starter-web'
    

    As Jackson core classes come with it.

    0 讨论(0)
  • 2020-11-27 05:37

    Add the below dependency to your pom.xml:

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.5.0</version>
    </dependency>
    
    0 讨论(0)
  • 2020-11-27 05:38

    I was facing same issue. I did not put @ResponseBody since I was using @RestController. But still I was getting error because I did not put the getter/setter method for the Company class. So after putting the getter/setter my problem was resolved.

    0 讨论(0)
提交回复
热议问题