Serializable class with unserializable injected member in JAVA

Iceglaze

I have a serializable class which has some members injected from guice module. However, these members are unserializable and I can't force the declaration of them with Serializable interface. How shall I write readObject and writeObject functions for this class to support the serializing the instance of this class?

AlexR

You can either declare these fields as transient to prevent automatic serialization or implement your own readObject and writeObject. The implementation will depend on your application. If after deserialization you can stand without the not serializable members, just ignore them. If you need them you have to find a way to get them.

In your case these are Guice-injected objects. If you are planning to deserialize your object in context of Guice you have to inject these dependencies. I do not know Guice enough but in Spring I know 2 ways:

  1. fetch these object programmatically from current Spring (Guice in your case) application context.
  2. Spring has factory that can inject all needed dependencies itself. I believe that Guice should have similar functionality.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Java Serializable 객체

분류에서Dev

Class has no member "Class"

분류에서Dev

How to register a class with a dependency injected constructor? (SimpleIoC)

분류에서Dev

Issue with declaration of Map<String,Class<? extends Serializable>>

분류에서Dev

Lambda function as class member

분류에서Dev

Is class member declaration not a statement?

분류에서Dev

Member in child class a reference to parent member?

분류에서Dev

Why is a byte[] of 0 Length being injected into my class?

분류에서Dev

Using getline with ifstream class member

분류에서Dev

Python: Hide member of base class in derived class

분류에서Dev

Creating a class instance as a member of another class

분류에서Dev

accessing the member of a class of pointer array of another class

분류에서Dev

Passing a member function of a class to a parameter outside the class

분류에서Dev

`In instantiation of [template class] [member] is protected [. . .] [public member] is inaccessible'

분류에서Dev

Is it possible to define a virtual static member on a delphi class?

분류에서Dev

Call member function when class type is not known

분류에서Dev

Cannot access private member declared in class

분류에서Dev

Forcing initialization of static data member of template class

분류에서Dev

C++ class member check if not a template

분류에서Dev

Resolve ambiguousness of a base template class member

분류에서Dev

my class does not have a member property

분류에서Dev

Injected-Class-Name이 발생하면 어떻게됩니까? (C ++)

분류에서Dev

calling method in template class in template member function of another class

분류에서Dev

Accessing derived class member from base class pointer

분류에서Dev

Segfault when using std::function class member with compiler optimizations

분류에서Dev

unique_ptr as class member and move semantics fail to compile with clang

분류에서Dev

how can I use cudaStreamAddCallback() with a class member method?

분류에서Dev

sizeof C++ class from static member function

분류에서Dev

How can I access public member of private package class?

Related 관련 기사

  1. 1

    Java Serializable 객체

  2. 2

    Class has no member "Class"

  3. 3

    How to register a class with a dependency injected constructor? (SimpleIoC)

  4. 4

    Issue with declaration of Map<String,Class<? extends Serializable>>

  5. 5

    Lambda function as class member

  6. 6

    Is class member declaration not a statement?

  7. 7

    Member in child class a reference to parent member?

  8. 8

    Why is a byte[] of 0 Length being injected into my class?

  9. 9

    Using getline with ifstream class member

  10. 10

    Python: Hide member of base class in derived class

  11. 11

    Creating a class instance as a member of another class

  12. 12

    accessing the member of a class of pointer array of another class

  13. 13

    Passing a member function of a class to a parameter outside the class

  14. 14

    `In instantiation of [template class] [member] is protected [. . .] [public member] is inaccessible'

  15. 15

    Is it possible to define a virtual static member on a delphi class?

  16. 16

    Call member function when class type is not known

  17. 17

    Cannot access private member declared in class

  18. 18

    Forcing initialization of static data member of template class

  19. 19

    C++ class member check if not a template

  20. 20

    Resolve ambiguousness of a base template class member

  21. 21

    my class does not have a member property

  22. 22

    Injected-Class-Name이 발생하면 어떻게됩니까? (C ++)

  23. 23

    calling method in template class in template member function of another class

  24. 24

    Accessing derived class member from base class pointer

  25. 25

    Segfault when using std::function class member with compiler optimizations

  26. 26

    unique_ptr as class member and move semantics fail to compile with clang

  27. 27

    how can I use cudaStreamAddCallback() with a class member method?

  28. 28

    sizeof C++ class from static member function

  29. 29

    How can I access public member of private package class?

뜨겁다태그

보관