1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.message;
18
19 import java.io.IOException;
20 import java.io.ObjectInputStream;
21 import java.io.ObjectOutputStream;
22 import java.io.Serializable;
23
24
25
26
27 public class ObjectMessage implements Message, Serializable {
28
29 private static final long serialVersionUID = -5903272448334166185L;
30
31 private transient Object obj;
32
33
34
35
36
37 public ObjectMessage(Object obj) {
38 if (obj == null) {
39 obj = "null";
40 }
41 this.obj = obj;
42 }
43
44
45
46
47
48 public String getFormattedMessage() {
49 return obj.toString();
50 }
51
52
53
54
55
56 public String getFormat() {
57 return obj.toString();
58 }
59
60
61
62
63
64 public Object[] getParameters() {
65 return new Object[]{obj};
66 }
67
68 @Override
69 public boolean equals(Object o) {
70 if (this == o) {
71 return true;
72 }
73 if (o == null || getClass() != o.getClass()) {
74 return false;
75 }
76
77 ObjectMessage that = (ObjectMessage) o;
78
79 return !(obj != null ? !obj.equals(that.obj) : that.obj != null);
80 }
81
82 @Override
83 public int hashCode() {
84 return obj != null ? obj.hashCode() : 0;
85 }
86
87 @Override
88 public String toString() {
89 return "ObjectMessage[obj=" + obj.toString() + "]";
90 }
91
92 private void writeObject(ObjectOutputStream out) throws IOException {
93 out.defaultWriteObject();
94 if (obj instanceof Serializable) {
95 out.writeObject(obj);
96 } else {
97 out.writeObject(obj.toString());
98 }
99 }
100
101 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
102 in.defaultReadObject();
103 obj = in.readObject();
104 }
105 }