JSON 序列化时的 jsonrpc4j null
jsonrpc4j null on JSON serialization
我从下面的 class CleengAPI.java
中的 jsonrpc4j
得到一个 null 错误,方法 rpc.listCustomers(publisherToken, offset, limit);
被调用以序列化以下客户 JSON 列表,该列表由 jsonrpc4j
正确下载并显示在调试语句中,但 JSON 未有效序列化导致空错误。
客户名单JSON
{
"result": [
{
"email": "",
"firstName": "xx",
"lastName": "xx",
"dateOfBirth": "",
"country": "US",
"companyName": "",
"phoneNumber": "",
"addressLine1": null,
"addressLine2": null,
"city": null,
"state": null,
"postalCode": null,
"regDate": "2019-12-24 07:06:46",
"lastLoginDate": "2019-12-24 07:06:46",
"transactions": "",
"payment": "",
"termsAccepted": "no",
"marketingOptIn": "no",
"lastUserIp": "xx.xx.x.x"
},
{
"email": "11@gmail.com",
"firstName": "xx",
"lastName": "xx",
"dateOfBirth": "",
"country": "US",
"companyName": "",
"phoneNumber": "",
"addressLine1": null,
"addressLine2": null,
"city": null,
"state": null,
"postalCode": null,
"regDate": "2019-02-12 02:10:57",
"lastLoginDate": "2019-03-19 17:10:28",
"transactions": "1",
"payment": "visa",
"termsAccepted": "no",
"marketingOptIn": "yes",
"lastUserIp": "xxx.xxx.xx.x"
}
],
"id": "854190206",
"error": null,
"jsonrpc": "2.0"
}
Class CleengAPI
import java.net.MalformedURLException;
import java.net.URL;
import com.googlecode.jsonrpc4j.JsonRpcHttpClient;
import com.googlecode.jsonrpc4j.JsonRpcParam;
import com.googlecode.jsonrpc4j.ProxyUtil;
import com.jahtoe.getner.domain.AccessStatus;
import com.jahtoe.getner.domain.Items;
import com.jahtoe.getner.domain.ListCustomers;
import com.jahtoe.getner.domain.ListCustomerSubscription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CleengApi {
private CleengRpc rpc;
public static final Logger LOG = LoggerFactory.getLogger(CleengApi.class);
private interface CleengRpc {
Items<ListCustomers> listCustomers(
@JsonRpcParam(value = "publisherToken") String publisherToken,
@JsonRpcParam(value = "offset") int offset,
@JsonRpcParam(value = "limit") int limit);
}
public CleengApi() throws MalformedURLException {
makeRpc("https://api.cleeng.com/3.0/json-rpc");
}
private void makeRpc(String apiUrl) throws MalformedURLException {
JsonRpcHttpClient client = new JsonRpcHttpClient(new URL(apiUrl));
rpc = ProxyUtil.createClientProxy(getClass().getClassLoader(), CleengRpc.class, client);
}
public Items<ListCustomers> ListCustomer(String publisherToken, int offset, int limit) {
return rpc.listCustomers(publisherToken, offset, limit);
}
}
Class ListCustomers 进行序列化 JSON
import java.io.Serializable;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonSerialize(include=JsonSerialize.Inclusion.NON_EMPTY)
public class ListCustomers implements Serializable {
private static final long serialVersionUID = 1L;
public String email;
public String firstName;
public String lastName;
public String dateOfBirth;
public String country;
public String companyName;
public String phoneNumber;
public Object addressLine1;
public Object addressLine2;
public Object city;
public Object state;
public Object postalCode;
public String regDate;
public String lastLoginDate;
public String transactions;
public String payment;
public String termsAccepted;
public String marketingOptIn;
public String lastUserIp;
}
用于创建 CleanAPI 并执行 ListCustomers 下载和序列化的代码段
CleengApi api = new
allListCustomer = api.ListCustomer(publisherToken, 0, 50);
POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jahtoe.XX</groupId>
<artifactId>XX</artifactId>
<version>1</version>
<packaging>jar</packaging>
<name>GregGetner</name>
<description>ETL: Cleeng to Zapier</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.github.briandilley.jsonrpc4j</groupId>
<artifactId>jsonrpc4j</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
项Class
package com.cleeng.apiv3.domain;
import java.io.Serializable;
public class Items<X> implements Serializable {
private static final long serialVersionUID = 1L;
public int totalItemCount;
public java.util.Vector<X> items;
}
我不确定如何调试它,因为消息只是一个词 null
如有任何帮助,我们将不胜感激。
问候
康特
所以发生的事情是 API 返回的 JSON 的以下样式需要项目 class
{
"result": {
"items": [{
"offerId": "S321834685_US",
"status": "active",
"expiresAt": 15869957,
"nextPaymentPrice": 79,
"nextPaymentCurrency": "USD",
"paymentGateway": "adyen",
"paymentMethod": "visa"
}],
"totalItemCount": 1
},
"id": "299789347",
"error": null,
"jsonrpc": "2.0"
}
但是这种样式需要一个列表。我正在使用这种样式的项目,这会导致空值。
{
"result": [
{
"email": "",
"firstName": "vvv",
"lastName": "wwwww",
"dateOfBirth": "",
"country": "US",
"companyName": "",
"phoneNumber": "",
"addressLine1": null,
"addressLine2": null,
"city": null,
"state": null,
"postalCode": null,
"regDate": "2019-12-24 07:06:46",
"lastLoginDate": "2019-12-24 07:06:46",
"transactions": "",
"payment": "",
"termsAccepted": "no",
"marketingOptIn": "no",
"lastUserIp": "xx.xxx.xxx.xxx"
},
我从下面的 class CleengAPI.java
中的 jsonrpc4j
得到一个 null 错误,方法 rpc.listCustomers(publisherToken, offset, limit);
被调用以序列化以下客户 JSON 列表,该列表由 jsonrpc4j
正确下载并显示在调试语句中,但 JSON 未有效序列化导致空错误。
客户名单JSON
{
"result": [
{
"email": "",
"firstName": "xx",
"lastName": "xx",
"dateOfBirth": "",
"country": "US",
"companyName": "",
"phoneNumber": "",
"addressLine1": null,
"addressLine2": null,
"city": null,
"state": null,
"postalCode": null,
"regDate": "2019-12-24 07:06:46",
"lastLoginDate": "2019-12-24 07:06:46",
"transactions": "",
"payment": "",
"termsAccepted": "no",
"marketingOptIn": "no",
"lastUserIp": "xx.xx.x.x"
},
{
"email": "11@gmail.com",
"firstName": "xx",
"lastName": "xx",
"dateOfBirth": "",
"country": "US",
"companyName": "",
"phoneNumber": "",
"addressLine1": null,
"addressLine2": null,
"city": null,
"state": null,
"postalCode": null,
"regDate": "2019-02-12 02:10:57",
"lastLoginDate": "2019-03-19 17:10:28",
"transactions": "1",
"payment": "visa",
"termsAccepted": "no",
"marketingOptIn": "yes",
"lastUserIp": "xxx.xxx.xx.x"
}
],
"id": "854190206",
"error": null,
"jsonrpc": "2.0"
}
Class CleengAPI
import java.net.MalformedURLException;
import java.net.URL;
import com.googlecode.jsonrpc4j.JsonRpcHttpClient;
import com.googlecode.jsonrpc4j.JsonRpcParam;
import com.googlecode.jsonrpc4j.ProxyUtil;
import com.jahtoe.getner.domain.AccessStatus;
import com.jahtoe.getner.domain.Items;
import com.jahtoe.getner.domain.ListCustomers;
import com.jahtoe.getner.domain.ListCustomerSubscription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CleengApi {
private CleengRpc rpc;
public static final Logger LOG = LoggerFactory.getLogger(CleengApi.class);
private interface CleengRpc {
Items<ListCustomers> listCustomers(
@JsonRpcParam(value = "publisherToken") String publisherToken,
@JsonRpcParam(value = "offset") int offset,
@JsonRpcParam(value = "limit") int limit);
}
public CleengApi() throws MalformedURLException {
makeRpc("https://api.cleeng.com/3.0/json-rpc");
}
private void makeRpc(String apiUrl) throws MalformedURLException {
JsonRpcHttpClient client = new JsonRpcHttpClient(new URL(apiUrl));
rpc = ProxyUtil.createClientProxy(getClass().getClassLoader(), CleengRpc.class, client);
}
public Items<ListCustomers> ListCustomer(String publisherToken, int offset, int limit) {
return rpc.listCustomers(publisherToken, offset, limit);
}
}
Class ListCustomers 进行序列化 JSON
import java.io.Serializable;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonSerialize(include=JsonSerialize.Inclusion.NON_EMPTY)
public class ListCustomers implements Serializable {
private static final long serialVersionUID = 1L;
public String email;
public String firstName;
public String lastName;
public String dateOfBirth;
public String country;
public String companyName;
public String phoneNumber;
public Object addressLine1;
public Object addressLine2;
public Object city;
public Object state;
public Object postalCode;
public String regDate;
public String lastLoginDate;
public String transactions;
public String payment;
public String termsAccepted;
public String marketingOptIn;
public String lastUserIp;
}
用于创建 CleanAPI 并执行 ListCustomers 下载和序列化的代码段
CleengApi api = new
allListCustomer = api.ListCustomer(publisherToken, 0, 50);
POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jahtoe.XX</groupId>
<artifactId>XX</artifactId>
<version>1</version>
<packaging>jar</packaging>
<name>GregGetner</name>
<description>ETL: Cleeng to Zapier</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.github.briandilley.jsonrpc4j</groupId>
<artifactId>jsonrpc4j</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
项Class
package com.cleeng.apiv3.domain;
import java.io.Serializable;
public class Items<X> implements Serializable {
private static final long serialVersionUID = 1L;
public int totalItemCount;
public java.util.Vector<X> items;
}
我不确定如何调试它,因为消息只是一个词 null
如有任何帮助,我们将不胜感激。
问候 康特
所以发生的事情是 API 返回的 JSON 的以下样式需要项目 class
{
"result": {
"items": [{
"offerId": "S321834685_US",
"status": "active",
"expiresAt": 15869957,
"nextPaymentPrice": 79,
"nextPaymentCurrency": "USD",
"paymentGateway": "adyen",
"paymentMethod": "visa"
}],
"totalItemCount": 1
},
"id": "299789347",
"error": null,
"jsonrpc": "2.0"
}
但是这种样式需要一个列表。我正在使用这种样式的项目,这会导致空值。
{
"result": [
{
"email": "",
"firstName": "vvv",
"lastName": "wwwww",
"dateOfBirth": "",
"country": "US",
"companyName": "",
"phoneNumber": "",
"addressLine1": null,
"addressLine2": null,
"city": null,
"state": null,
"postalCode": null,
"regDate": "2019-12-24 07:06:46",
"lastLoginDate": "2019-12-24 07:06:46",
"transactions": "",
"payment": "",
"termsAccepted": "no",
"marketingOptIn": "no",
"lastUserIp": "xx.xxx.xxx.xxx"
},