Spring POST请求不支持的媒体类型415

phi

我有一个基于本教程的简单Spring 4项目我正在尝试实现RESTful接口。现在,我在处理POST请求时遇到了麻烦。当我尝试发布JSON对象时,出现以下错误:

    {
        "timestamp":1428785473020,
        "status":415,
        "error":"Unsupported Media Type",
        "exception":"org.springframework.web.HttpMediaTypeNotSupportedException",
        "message":"Content type 'application/octet-stream' not supported",
        "path":"/markers/new"
    }

如果我添加具有application / json值的Content-Type标头,则具有以下内容:

{
    "timestamp":1428785073247,
    "status":400,
    "error":"BadRequest",
    "exception":"org.springframework.http.converter.HttpMessageNotReadableException",
    "message":"Could not read JSON: No suitable constructor found for type 
        [simple type, class org.elsys.internetprogramming.trafficspy.server.Marker]: 
        can not instantiate from JSON object (need to add/enable type information?)
        at [Source: java.io.PushbackInputStream@19e19767; line: 1, column: 2]; 
        nested exception is com.fasterxml.jackson.databind.JsonMappingException: 
        No suitable constructor found for type [simple type, class 
        org.elsys.internetprogramming.trafficspy.server.Marker]: can not 
        instantiate from JSON object (need to add/enable type information?)
        at [Source: java.io.PushbackInputStream@19e19767; line: 1, column: 2]",
    "path":"/markers/new"
}

下面是代码:MarkerController.java

@Controller
public class MarkerController {
    private final AtomicLong id = new AtomicLong();
    private Logger logger = Logger.getLogger(MarkerController.class.getName());

    @RequestMapping(value="/markers", method=RequestMethod.GET)
    public @ResponseBody String getMarkers(@RequestParam(value="city", defaultValue="") String city) {
        logger.info("HANDLE GET REQUEST");
        return "{\"id\":\"1\"}";
    }

    @RequestMapping(value="/markers/new", method=RequestMethod.POST)
    public @ResponseBody Marker putMarker(@RequestBody Marker marker) {
        logger.info("HANDLE POST REQUEST");
        return marker;
    }

}

Marker.java

public class Marker {
    private long id;
    private double longitude;
    private double latitude;

    private final String address;

    public Marker(long id, double longitude, double latitude, String address) {
        this.id = id;
        this.longitude = longitude;
        this.latitude = latitude;
        this.address = address;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
}

您是否知道导致此问题的原因以及如何解决?谢谢!

JB Nizet

没有找到适合类型[简单类型,类org.elsys.internetprogramming.trafficspy.server.Marker]的构造函数

您的Marker类没有默认的构造函数。因此,杰克逊没有办法实例化它。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Spring POST请求不支持的媒体类型415

来自分类Dev

Spring MVC + AngularJS 415不支持的媒体类型

来自分类Dev

JSON加Spring MVC 3.2错误415(不支持的媒体类型)

来自分类Dev

Spring MVC Ajax文件上传导致415(不支持的媒体类型)

来自分类Dev

415-不支持的媒体类型错误| angularjs + Spring3.2

来自分类Dev

415 Spring应用程序中不支持POST请求的MediaType

来自分类Dev

使用Spring RestTemplate客户端的Spring Boot Actuator关闭端点:错误415不支持的媒体类型

来自分类Dev

带有多部分请求的Spring Boot不支持的媒体类型

来自分类Dev

当我将json发送到spring控制器时,415不支持的媒体类型

来自分类Dev

使用Spring Security登录:请求方法'POST'不支持

来自分类Dev

Spring MVC-不支持请求方法“ POST”

来自分类Dev

Spring Security 4:不支持请求方法“ POST”

来自分类Dev

Spring Security不支持请求方法“ POST”

来自分类Dev

请求方法'POST'不支持Spring Boot

来自分类Dev

Spring Boot新手-请求方法'POST'不支持

来自分类Dev

Jersey 415不支持的媒体类型

来自分类Dev

Curl 415不支持的媒体类型

来自分类Dev

HTTP 415不支持的媒体类型

来自分类Dev

415不支持的媒体类型+弹簧

来自分类Dev

415不支持的媒体类型HTTP

来自分类Dev

升级到1.3.0后spring-boot / health端点不支持媒体类型xml

来自分类Dev

升级到1.3.0后spring-boot / health端点不支持媒体类型xml

来自分类Dev

Spring MVC HTTP状态405-请求方法'POST'不支持-骨干请求

来自分类Dev

将 get 请求转发到 post 请求的 jattempting 返回不支持的错误 Spring

来自分类Dev

HTTP状态405-具有Spring Security的Spring MVC不支持请求方法'POST'

来自分类Dev

Spring MVC的CURL POST请求给出405方法'POST'不支持

来自分类Dev

上载文件时不支持Spring MVC错误405请求方法'POST'

来自分类Dev

Spring MVC上传文件-HTTP状态405-不支持请求方法“ POST”

来自分类Dev

Spring Boot - 不支持请求方法“POST”(不允许方法)

Related 相关文章

  1. 1

    Spring POST请求不支持的媒体类型415

  2. 2

    Spring MVC + AngularJS 415不支持的媒体类型

  3. 3

    JSON加Spring MVC 3.2错误415(不支持的媒体类型)

  4. 4

    Spring MVC Ajax文件上传导致415(不支持的媒体类型)

  5. 5

    415-不支持的媒体类型错误| angularjs + Spring3.2

  6. 6

    415 Spring应用程序中不支持POST请求的MediaType

  7. 7

    使用Spring RestTemplate客户端的Spring Boot Actuator关闭端点:错误415不支持的媒体类型

  8. 8

    带有多部分请求的Spring Boot不支持的媒体类型

  9. 9

    当我将json发送到spring控制器时,415不支持的媒体类型

  10. 10

    使用Spring Security登录:请求方法'POST'不支持

  11. 11

    Spring MVC-不支持请求方法“ POST”

  12. 12

    Spring Security 4:不支持请求方法“ POST”

  13. 13

    Spring Security不支持请求方法“ POST”

  14. 14

    请求方法'POST'不支持Spring Boot

  15. 15

    Spring Boot新手-请求方法'POST'不支持

  16. 16

    Jersey 415不支持的媒体类型

  17. 17

    Curl 415不支持的媒体类型

  18. 18

    HTTP 415不支持的媒体类型

  19. 19

    415不支持的媒体类型+弹簧

  20. 20

    415不支持的媒体类型HTTP

  21. 21

    升级到1.3.0后spring-boot / health端点不支持媒体类型xml

  22. 22

    升级到1.3.0后spring-boot / health端点不支持媒体类型xml

  23. 23

    Spring MVC HTTP状态405-请求方法'POST'不支持-骨干请求

  24. 24

    将 get 请求转发到 post 请求的 jattempting 返回不支持的错误 Spring

  25. 25

    HTTP状态405-具有Spring Security的Spring MVC不支持请求方法'POST'

  26. 26

    Spring MVC的CURL POST请求给出405方法'POST'不支持

  27. 27

    上载文件时不支持Spring MVC错误405请求方法'POST'

  28. 28

    Spring MVC上传文件-HTTP状态405-不支持请求方法“ POST”

  29. 29

    Spring Boot - 不支持请求方法“POST”(不允许方法)

热门标签

归档