使用RestTemplate序列化JSON数据时出现问题

时间:2019-02-12 15:58:12

标签: java spring rest spring-boot http

我正在尝试使用RestTemplate通过GET调用从我们的一个API序列化JSON数据。

当它实际上是JSON响应时,就好像getForObject方法在API URL中期望XML值一样。从我完成的所有搜索中,该方法应该使用JSON,而不是XML-那么怎么了?

我们非常感谢您的帮助。

控制器

public partial class WVGUIApp : Application
    {
    IPEndPoint sendersEndPoint;
    UdpClient listener;

    void AppStartup(object sender, StartupEventArgs args)
    {
        LoadMachineData();
        MainWindow mainWindow = new MainWindow();
        mainWindow.Show();

        listener = new UdpClient
        {
            ExclusiveAddressUse = false
        };
        listener.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
        IPAddress ip = System.Net.IPAddress.Parse("10.178.100.111");
        int ipInt = BitConverter.ToInt32(ip.GetAddressBytes(), 0);
        IPEndPoint endPoint = new IPEndPoint(ipInt, 60811); //new IPEndPoint(IPAddress.Any, listenPort); this might allow me not to know the IP of this local device!
        listener.Client.Bind(endPoint);
        listener.BeginReceive(new AsyncCallback(Receive), null);
        //Thread.Sleep(20000);

    }

    private void Receive(IAsyncResult res)
    {
        byte[] bytes = listener.EndReceive(res, ref sendersEndPoint);
        listener.BeginReceive(new AsyncCallback(Receive), null);
        Console.WriteLine("Received");
    }
}

应用

RestTemplate appApi = new RestTemplate();
Application app = appApi.getForObject("api url", Application.class);

响应“ API URL”的示例将给出:

import lombok.Data;

@Data
public class Application {
    ApplicationDetails value;

    @Data
    public class ApplicationDetails {
        String salsaId;
        String itSystemName;
        String businessOwner;
        String businessOwnershipLob;
        String leadProgramme;
        String lifecycleStage;
    }
}

在我看来,这应该都能正常工作,并且该api调用的响应应保存在应用程序对象“ app”中。但是,运行时出现以下错误:

{
  "value": {
    "salsaId": "data",
    "itSystemName": "data",
    "businessOwner": "data",
    "businessOwnershipLob": "data",
    "leadProgramme": "data",
    "lifecycleStage": "data"
  }
}

0 个答案:

没有答案