小编Alt*_*ava的帖子

如何以 JSON 格式发送整数值并在 REST Controller 中接收?

我有一个 REST 控制器,我在其中编写了此代码

@PostMapping(value = "/otp")
public void otp(@RequestBody Integer mobile) {

    System.out.println(" Mobile = "+mobile);
}
Run Code Online (Sandbox Code Playgroud)

我使用以下输入从 Postman 调用此方法

URL : localhost:8080/otp

Body

{
    "mobile":123456
}
Run Code Online (Sandbox Code Playgroud)

但我收到以下异常

org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Can not deserialize instance of java.lang.Integer out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.Integer out of START_OBJECT token
Run Code Online (Sandbox Code Playgroud)

如果我将 String 作为这样的参数

@PostMapping(value = "/otp")
public void otp(@RequestBody String mobile) {

    System.out.println(" Mobile = "+mobile);
}
Run Code Online (Sandbox Code Playgroud)

并将输入作为

{
    "mobile":123456
}
Run Code Online (Sandbox Code Playgroud)

现在它在控制台中打印如下

 Mobile …
Run Code Online (Sandbox Code Playgroud)

java spring json spring-boot spring-restcontroller

4
推荐指数
1
解决办法
2万
查看次数

项目构建错误:不可解析的 POM /pom.xml:实体引用名称不能包含字符 ='(位置:START_TAG 可见 ...)

我正在使用 Spring Boot 使用 SOAP Web 服务。要将 WSDL 转换为 Java 绑定(域)类,我正在使用maven-jaxb2-plugin.

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.13.1</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <schemaLanguage>WSDL</schemaLanguage>
        <generateDirectory>${project.basedir}/src/main/java</generateDirectory>
        <generatePackage>com.test.consume</generatePackage>
        <schemas>
            <schema>
                <url>https://test.co.in/cordys/WSDLGateway.wcp?service=http://schemas.cordys.com/default/getIDV&organization=o=B2C,cn=cordys,cn=defaultInst106,o=mydomain.com</url>
            </schema>
        </schemas>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

<url>标签中我写了这样的 WSDL URL

<url>https://test.co.in/cordys/WSDLGateway.wcp?service=http://schemas.cordys.com/default/getIDV&organization=o=B2C,cn=cordys,cn=defaultInst106,o=mydomain.com</url>
Run Code Online (Sandbox Code Playgroud)

但是我在 pom.xml 中遇到了以下问题

Project build error: Non-parseable POM /home/altaf/My Workspace/TestConsumer/pom.xml: entity reference name can not contain character =' (position: START_TAG seen ...wcp?service=http://schemas.cordys.com/default/getIDV&organization=... @64:117)

如何解决这个问题?

java web-services pom.xml maven spring-boot

2
推荐指数
1
解决办法
5708
查看次数