2016-11-05 3 views
0

У меня есть WebService, который посылает список Автомобиль на клиента веб-сервиса, транспортное средство реализуется следующим образом:Сериализация объекта, содержащего поле Список

public class Vehicle implements Serializable{ 

    private static final long serialVersionUID = -8169481181178317205L; 
    private final String id; 
    private final LocalDate depositDate; 
    private final double price; 

    private final ArrayList<Integer> scores = new ArrayList<>(); 
    private final ArrayList<String> comments = new ArrayList<>(); 

    private Optional<Renter> renter = Optional.empty(); 
    private int rentalNumber = 0; 
} 

Как вы можете видеть, объект транспортного средства содержит 2 поля которые являются ArrayList. Когда я хочу создать веб-службу, у меня есть несколько предупреждений о том, что Vehicle (который является единственным объектом, который я хочу отправить по сети) и другим объектом, не соблюдает соглашение JAX-RPC и может не отправляться должным образом.

Как избавиться от этих предупреждений? Это обязательство?

Первым решением, которое я реализовал, было преобразование списка в массив, но есть ли что-нибудь еще?

EDIT 5: Проблема возникает в том, чтобы добавить параметр в методе я хочу использовать для веб-service.I пытался добавить метод как этот:

public StatePayment lol(int lol){ 

    return StatePayment.DENIED; 
} 

И Web Services Creation программное обеспечение вернуло мне ту же ошибку. Нельзя ли добавить метод с параметрами?

EDIT4: Я создал поддельный метод, чтобы проверить, в чем проблема. Похоже, что когда у меня был параметр в сигнатуре метода, у меня есть прецедентная ошибка.

//Not working code 
public StatePayment lol(Buyer buyer){ 

     return StatePayment.DENIED; 
    } 

//Working code 
public StatePayment lol(Buyer buyer){ 

     return StatePayment.DENIED; 
    } 

Я думаю, проблема связана с покупателем, но я не могу понять, что это может быть.

EDIT 3: Когда я хочу создать WebService по «новый-> WebService-> Выбор методов У меня есть следующее сообщение об ошибке:.

IWAB0398E Error in generating WSDL from Java: >java.lang.IllegalStateException: Error looking for paramter names in >bytecode: unexpected bytes in file

Является ли это проблемой сериализации

? ошибка происходит, когда я выбираю этот метод:

public int proceedToPayment(Buyer buyer) { 

     //Calcul du prix total du shoppingCart 
     long totalPrice = 0; 
     for(Vehicle v : buyer.getShoppingCart()) { 
      totalPrice += v.getPrice(); 
     } 

     Bank buyerBank = buyer.getBank(); 

     //Convertir totalPrice en euros vers la monnaie du Buyer. 

     if(buyerBank.bankTransaction(totalPrice, buyer) == StatePayment.DENIED) { 
      return 0; 
     } 

     removeShoppingCartFromBDD(buyer.getShoppingCart()); 
     return 1; 
    } 

EDIT 2:. чтобы быть более ясным, мой главный вопрос в том, я вынужден, чтобы избавиться от всех этих предупредительных сообщений S зная, что единственный объект, который я буду передавать по сети являются Vehicle, и те, которые находятся внутри автомобиля (наймодатель)

EDIT 1: Предупреждение Сообщение

The service class "MlvDataBaseImpl" does not comply to one or more requirements of the JAX-RPC 1.1 specification, and may not deploy or function correctly.

The method "exportObject" on the service class "MlvDataBaseImpl" is overloaded. Overloaded methods are allowed by chapter 5.5.5 of the JAX-RPC 1.1 specification, however, some JAX-RPC 1.1 compliant tools may not allow overloaded methods or may generate WSDL with overloaded operations as contrary to rule R2304 of the WS-I Basic Profile.

The value type "MlvDataBase" used via the service class "MlvDataBaseImpl" does not have a public default constructor. Chapter 5.4 of the JAX-RPC 1.1 specification requires a value type to have a public default constructor, otherwise, a JAX-RPC 1.1 compliant Web service engine may be unable to construct an instance of the value type during deserialization.

The value type "Renter" used via the service class "MlvDataBaseImpl" does not have a public default constructor. Chapter 5.4 of the JAX-RPC 1.1 specification requires a value type to have a public default constructor, otherwise a JAX-RPC 1.1 compliant Web service engine may be unable to construct an instance of the value type during deserialization.

The value type "Vehicle" used via the service class "MlvDataBaseImpl" does not have a public default constructor. Chapter 5.4 of the JAX-RPC 1.1 specification requires a value type to have a public default constructor, otherwise a JAX-RPC 1.1 compliant Web service engine may be unable to construct an instance of the value type during deserialization.

The value type "Buyer" used via the service class "MlvDataBaseImpl" does not have a public default constructor. Chapter 5.4 of the JAX-RPC 1.1 specification requires a value type to have a public default constructor, otherwise, a JAX-RPC 1.1 compliant Web service engine may be unable to construct an instance of the value type during deserialization.

The method "registerVehicle" on the service class "MlvDataBaseImpl" uses a data type, "java.time.LocalDate", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The method "getRentableVehicles" on the service class "MlvDataBaseImpl" uses a data type, "java.util.List", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The method "clone" on the service class "MlvDataBaseImpl" uses a data type, "java.lang.Object", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The method "exportObject" on the service class "MlvDataBaseImpl" uses a data type, "java.rmi.server.RemoteStub", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The method "exportObject" on the service class "MlvDataBaseImpl" uses a data type, "java.rmi.Remote", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The method "exportObject" on the service class "MlvDataBaseImpl" uses a data type, "java.rmi.Remote", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The method "exportObject" on the service class "MlvDataBaseImpl" uses a data type, "java.rmi.Remote", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The method "exportObject" on the service class "MlvDataBaseImpl" uses a data type, "java.rmi.Remote", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The method "exportObject" on the service class "MlvDataBaseImpl" uses a data type, "java.rmi.Remote", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The method "exportObject" on the service class "MlvDataBaseImpl" uses a data type, "java.rmi.server.RMIClientSocketFactory", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The method "exportObject" on the service class "MlvDataBaseImpl" uses a data type, "java.rmi.server.RMIServerSocketFactory", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The method "unexportObject" on the service class "MlvDataBaseImpl" uses a data type, "java.rmi.Remote", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The method "setLog" on the service class "MlvDataBaseImpl" uses a data type, "java.io.OutputStream", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The method "getLog" on the service class "MlvDataBaseImpl" uses a data type, "java.io.PrintStream", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The method "getRef" on the service class "MlvDataBaseImpl" uses a data type, "java.rmi.server.RemoteRef", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The method "toStub" on the service class "MlvDataBaseImpl" uses a data type, "java.rmi.Remote", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The method "toStub" on the service class "MlvDataBaseImpl" uses a data type, "java.rmi.Remote", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The method "equals" on the service class "MlvDataBaseImpl" uses a data type, "java.lang.Object", that is not supported by the JAX-RPC specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The service class "MlvDataBaseImpl" does not have a public default constructor. Chapter 10.1 of the JAX-RPC 1.1 specification requires a service class to have a public default constructor, otherwise a JAX-RPC 1.1 compliant Web service engine may be unable to construct an instance of the service class to handle an incoming request message.

The field or property "declaringClass" on the value type "java.lang.Enum" used via the service class "MlvDataBaseImpl" has a data type, "java.lang.Class", that is not supported by the JAX-RPC 1.1 specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The field or property "depositDate" on the value type "Vehicle" used via the service class "MlvDataBaseImpl" has a data type, "java.time.LocalDate", that is not supported by the JAX-RPC 1.1 specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The field or property "comments" on the value type "Vehicle" used via the service class "MlvDataBaseImpl" has a data type, "java.util.List", that is not supported by the JAX-RPC 1.1 specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The field or property "scores" on the value type "Vehicle" used via the service class "MlvDataBaseImpl" has a data type, "java.util.List", that is not supported by the JAX-RPC 1.1 specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The field or property "declaringClass" on the value type "java.lang.Enum" used via the service class "MlvDataBaseImpl" has a data type, "java.lang.Class", that is not supported by the JAX-RPC 1.1 specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

The field or property "shoppingCart" on the value type "Buyer" used via the service class "MlvDataBaseImpl" has a data type, "java.util.ArrayList", that is not supported by the JAX-RPC 1.1 specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

+1

Можете ли вы добавить предупреждение на свой вопрос? Также вы должны изменить ArrayList в List: приватный финальный список comm = new ArrayList <>(); – user2026753

+0

Я загрузил сообщение. –

+0

Единственное предупреждение в этом огромном списке, которое ссылается на «Транспортное средство», похоже, единственное, что связано с отсутствием публичного конструктора по умолчанию. Итак, как насчет добавления общедоступного конструктора по умолчанию? –

ответ

0

Пожалуйста, посмотрите на этот пост JAXB annotations for nested element lists более подробности, как сериализовать списки.

Что касается предупреждений, вам нужно искать каждый в SO, есть много разных предметов.

Смежные вопросы