0
我已經生成的類與raml-to-jaxrs maven plugin(2.1.1-SNAPSHOT),並調用這樣與新澤西州代理客戶服務:新澤西州代理客戶端無法反序列化JSON響應從<a href="https://github.com/haba713/posti-smartship-client/blob/master/src/main/resources/root-resource-v1.raml" rel="nofollow noreferrer">this RAML file</a>腎錯構瘤生成的類
Client client = ClientBuilder.newClient();
Logger logger = Logger.getLogger(getClass().getName());
Feature feature = new LoggingFeature(logger, Level.INFO, null, null);
client.register(feature);
client.register(new PostiSmartShipAuthenticator(username, password));
WebTarget target = client.target(URI);
Addresses proxy = WebResourceFactory.newResource(Addresses.class, target);
GetAddressesAgentsResponse response = proxy.getAddressesAgents("ITELLASP", null, "51270", null, "FI", null);
INFO: 1 * Sending client request on thread main
1 > GET https://.../addresses/agents?type=ITELLASP&zip=51270&countryCode=FI
1 > Accept: application/json
1 > Authorization: Basic ...
INFO: 1 * Client response received on thread main
1 < 200
1 < Connection: Keep-Alive
1 < Content-Type: application/json;charset=UTF-8
1 < Date: Sun, 15 Oct 2017 10:38:53 GMT
1 < Keep-Alive: timeout=5, max=100
1 < Server: Apache
1 < Transfer-Encoding: chunked
[{"id":"512053201","name":"Pakettiautomaatti, S-market Kangasniemi","address1":"Otto Mannisen tie 10","address2":null,"zipcode":"51205","city":"KANGASNIEMI","state":null,"countryCode":"FI","contact":null,"phone":null,"fax":null,"email":null,"sms":null,"serviceType":null,"serviceCode":null,"openingHours":"ma-la 7.00 - 21.00, su 10.00 - 21.00"},{"id":"761053201","name":"Pakettiautomaatti, K-citymarket Pieksämäki","address1":"Kukkaroniementie 3","address2":null,"zipcode":"76105","city":"PIEKSÄMÄKI","state":null,"countryCode":"FI","contact":null,"phone":null,"fax":null,"email":null,"sms":null,"serviceType":null,"serviceCode":null,"openingHours":"ma-pe 8.00 - 21.00, la 8.00 - 20.00, su 11.00 - 18.00"},{"id":"408053201","name":"Pakettiautomaatti, S-market Vaajala","address1":"Asematie 1","address2":null,"zipcode":"40805","city":"VAAJAKOSKI","state":null,"countryCode":"FI","contact":null,"phone":null,"fax":null,"email":null,"sms":null,"serviceType":null,"serviceCode":null,"openingHours":"ma-la 7.00 - 22.00, su 10.00 - 22.00"},{"id":"409053201","name":"Pakettiautomaatti, S-market Säynätsalo","address1":"Parviaisentie 6","address2":null,"zipcode":"40905","city":"SÄYNÄTSALO","state":null,"countryCode":"FI","contact":null,"phone":null,"fax":null,"email":null,"sms":null,"serviceType":null,"serviceCode":null,"openingHours":"ma-la 7.00 - 21.00, su 10.00 - 21.00"},{"id":"405253201","name":"Pakettiautomaatti, S-market Kuokkala","address1":"Syöttäjänkatu 2","address2":null,"zipcode":"40525","city":"JYVÄSKYLÄ","state":null,"countryCode":"FI","contact":null,"phone":null,"fax":null,"email":null,"sms":null,"serviceType":null,"serviceCode":null,"openingHours":"ma-la 7.00 - 23.00, su 10.00 - 23.00"}]
然而,對象的陣列不能反序列化到GetAddressesAgentsResponse:
服務與對象的數組響應10Caused by: javax.json.bind.JsonbException: Can't deserialize JSON array into: class haba713.postismartship.resources.Addresses$GetAddressesAgentsResponse
at org.eclipse.yasson.internal.serializer.DeserializerBuilder.build(DeserializerBuilder.java:129)
at org.eclipse.yasson.internal.Unmarshaller.deserializeItem(Unmarshaller.java:56)
at org.eclipse.yasson.internal.Unmarshaller.deserialize(Unmarshaller.java:50)
at org.eclipse.yasson.internal.JsonBinding.deserialize(JsonBinding.java:45)
at org.eclipse.yasson.internal.JsonBinding.fromJson(JsonBinding.java:85)
at org.glassfish.jersey.jsonb.internal.JsonBindingProvider.readFrom(JsonBindingProvider.java:99)
at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:257)
at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:236)
at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1091)
at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:834)
at org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:363)
at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:936)
... 37 more
出於某種原因,插件似乎總是產生與com.fasterxml.jackson annotations類,即使我有
<generateTypesWith>
<value>jaxb</value>
</generateTypesWith>
在
pom.xml
。可能這不是真正的問題。
有效的依賴關係目前是
javax.ws.rs:javax.ws.rs-api:2.1
org.glassfish.jersey.core:jersey-client:2.26
org.glassfish.jersey.core:jersey-common:2.26
org.glassfish.jersey.ext:jersey-proxy-client:2.26
org.glassfish.jersey.inject:jersey-hk2:2.26
org.glassfish.jersey.media:jersey-media-jaxb:2.26
org.glassfish.jersey.media:jersey-media-json-binding:2.26
org.glassfish.jersey.media:jersey-media-json-jackson:2.26
org.raml.jaxrs:jaxrs-code-generator:2.1.1-SNAPSHOT
我應該使用一些其他的接口比這裏的地址?
Addresses proxy = WebResourceFactory.newResource(Addresses.class, target);
什麼應該改變,使反序列化工作?
親切的問候,
哈里·
我在[pom.xml]中使用[「jaxb]」(https://github.com/haba713/posti-smartship-client/blob/master/pom.xml#L136),但對於某些原因[模型文件](https://github.com/haba713/posti-smartship-client/tree/master/src/main/java/haba713/postismartship/model)有傑克遜註釋。 – haba713
嗯,我只是看着你的項目,你似乎用jsonschema來描述你的對象。它當然會被映射到json。 jaxb註釋只會被添加到raml定義的對象中。 如果你想從模式生成jaxb註釋(如舊的raml 0.8倍),你將不得不使用xml模式。 –