• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wuwen5 / hessian / 18062024814

27 Sep 2025 03:33AM UTC coverage: 71.737% (+0.4%) from 71.311%
18062024814

push

github

web-flow
feat: add InetSocketAddress serialization and deserialization support (#61)

* feat: add InetSocketAddress serialization and deserialization support

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

1764 of 2651 branches covered (66.54%)

Branch coverage included in aggregate %.

4244 of 5724 relevant lines covered (74.14%)

3.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.24
hessian2-codec/src/main/java/io/github/wuwen5/hessian/io/Hessian2SerializerFactory.java
1
/*
2
 * Copyright (c) 2001-2008 Caucho Technology, Inc.  All rights reserved.
3
 *
4
 * The Apache Software License, Version 1.1
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 *
10
 * 1. Redistributions of source code must retain the above copyright
11
 *    notice, this list of conditions and the following disclaimer.
12
 *
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in
15
 *    the documentation and/or other materials provided with the
16
 *    distribution.
17
 *
18
 * 3. The end-user documentation included with the redistribution, if
19
 *    any, must include the following acknowlegement:
20
 *       "This product includes software developed by the
21
 *        Caucho Technology (http://www.caucho.com/)."
22
 *    Alternately, this acknowlegement may appear in the software itself,
23
 *    if and wherever such third-party acknowlegements normally appear.
24
 *
25
 * 4. The names "Burlap", "Resin", and "Caucho" must not be used to
26
 *    endorse or promote products derived from this software without prior
27
 *    written permission. For written permission, please contact
28
 *    info@caucho.com.
29
 *
30
 * 5. Products derived from this software may not be called "Resin"
31
 *    nor may "Resin" appear in their names without prior written
32
 *    permission of Caucho Technology.
33
 *
34
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
35
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37
 * DISCLAIMED.  IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
38
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
39
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
40
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
42
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
43
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
44
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45
 *
46
 * @author Scott Ferguson
47
 */
48

49
package io.github.wuwen5.hessian.io;
50

51
import com.caucho.hessian.io.HessianRemoteObject;
52
import java.io.IOException;
53
import java.io.InputStream;
54
import java.io.Serializable;
55
import java.lang.annotation.Annotation;
56
import java.lang.ref.SoftReference;
57
import java.lang.ref.WeakReference;
58
import java.util.ArrayList;
59
import java.util.Calendar;
60
import java.util.Collection;
61
import java.util.Enumeration;
62
import java.util.HashMap;
63
import java.util.Iterator;
64
import java.util.List;
65
import java.util.Map;
66
import java.util.WeakHashMap;
67
import java.util.concurrent.ConcurrentHashMap;
68
import java.util.concurrent.ConcurrentMap;
69
import java.util.logging.Level;
70
import java.util.logging.Logger;
71
import lombok.Getter;
72
import lombok.Setter;
73
import lombok.SneakyThrows;
74

75
/**
76
 * Factory for returning serialization methods.
77
 */
78
public class Hessian2SerializerFactory implements ISerializerFactory {
79
    private static final Logger log = Logger.getLogger(Hessian2SerializerFactory.class.getName());
4✔
80

81
    private static final ClassLoader SYSTEM_CLASS_LOADER;
82

83
    private static final Map<String, HessianDeserializer> STATIC_TYPE_MAP;
84

85
    private static final WeakHashMap<ClassLoader, SoftReference<Hessian2SerializerFactory>> DEFAULT_FACTORY_REF_MAP =
4✔
86
            new WeakHashMap<>();
87

88
    private final ContextSerializerFactory contextFactory;
89
    private final WeakReference<ClassLoader> loaderRef;
90

91
    protected HessianSerializer defaultSerializer;
92

93
    /**
94
     * Additional factories
95
     */
96
    protected List<ISerializerFactory> factories = new ArrayList<>();
5✔
97

98
    protected CollectionSerializer collectionSerializer;
99
    protected MapSerializer mapSerializer;
100

101
    private HessianDeserializer hashMapDeserializer;
102
    private HessianDeserializer arrayListDeserializer;
103
    private final ConcurrentMap<Class<?>, HessianSerializer> cachedSerializerMap = new ConcurrentHashMap<>(8);
6✔
104
    private final ConcurrentMap<Class<?>, HessianDeserializer> cachedDeserializerMap = new ConcurrentHashMap<>(8);
6✔
105
    private final ConcurrentMap<String, HessianDeserializer> cachedTypeDeserializerMap = new ConcurrentHashMap<>();
5✔
106

107
    /**
108
     * -- SETTER --
109
     *  If true, non-serializable objects are allowed.
110
     * -- GETTER --
111
     *  If true, non-serializable objects are allowed.
112
     *
113
     */
114
    @Getter
115
    @Setter
116
    private boolean isAllowNonSerializable;
117

118
    private final boolean isEnableUnsafeSerializer = (UnsafeSerializer.isEnabled() && UnsafeDeserializer.isEnabled());
9!
119

120
    private final FieldDeserializer2Factory fieldDeserializer2Factory;
121

122
    private ClassFactory classFactory;
123

124
    public Hessian2SerializerFactory() {
125
        this(Thread.currentThread().getContextClassLoader());
4✔
126
    }
1✔
127

128
    public Hessian2SerializerFactory(ClassLoader loader) {
2✔
129
        loaderRef = new WeakReference<>(loader);
6✔
130

131
        contextFactory = ContextSerializerFactory.create(loader);
4✔
132

133
        if (isEnableUnsafeSerializer) {
3✔
134
            fieldDeserializer2Factory = new FieldDeserializer2FactoryUnsafe();
6✔
135
        } else {
136
            fieldDeserializer2Factory = new FieldDeserializer2Factory();
5✔
137
        }
138
    }
1✔
139

140
    public static Hessian2SerializerFactory createDefault() {
141
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
3✔
142

143
        synchronized (DEFAULT_FACTORY_REF_MAP) {
4✔
144
            SoftReference<Hessian2SerializerFactory> factoryRef = DEFAULT_FACTORY_REF_MAP.get(loader);
5✔
145

146
            Hessian2SerializerFactory factory = null;
2✔
147

148
            if (factoryRef != null) {
2✔
149
                factory = factoryRef.get();
4✔
150
            }
151

152
            if (factory == null) {
2✔
153
                factory = new Hessian2SerializerFactory();
4✔
154

155
                factoryRef = new SoftReference<>(factory);
5✔
156

157
                DEFAULT_FACTORY_REF_MAP.put(loader, factoryRef);
5✔
158
            }
159

160
            return factory;
4✔
161
        }
162
    }
163

164
    public ClassLoader getClassLoader() {
165
        return loaderRef.get();
5✔
166
    }
167

168
    /**
169
     * Set true if the collection serializer should send the java type.
170
     */
171
    public void setSendCollectionType(boolean isSendType) {
172
        if (collectionSerializer == null) {
×
173
            collectionSerializer = new CollectionSerializer();
×
174
        }
175

176
        collectionSerializer.setSendJavaType(isSendType);
×
177

178
        if (mapSerializer == null) {
×
179
            mapSerializer = new MapSerializer();
×
180
        }
181

182
        mapSerializer.setSendJavaType(isSendType);
×
183
    }
×
184

185
    /**
186
     * Adds a factory.
187
     */
188
    public void addFactory(ISerializerFactory factory) {
189
        factories.add(factory);
×
190
    }
×
191

192
    /**
193
     * Returns the serializer for a class.
194
     *
195
     * @param cl the class of the object that needs to be serialized.
196
     *
197
     * @return a serializer object for the serialization.
198
     */
199
    public HessianSerializer getObjectSerializer(Class<?> cl) throws HessianProtocolException {
200
        HessianSerializer serializer = getSerializer(cl);
4✔
201

202
        if (serializer instanceof ObjectSerializer) {
3✔
203
            return ((ObjectSerializer) serializer).getObjectSerializer();
4✔
204
        } else {
205
            return serializer;
2✔
206
        }
207
    }
208

209
    public Class<?> loadSerializedClass(String className) throws ClassNotFoundException {
210
        return getClassFactory().load(className);
5✔
211
    }
212

213
    public ClassFactory getClassFactory() {
214
        synchronized (this) {
4✔
215
            if (classFactory == null) {
3✔
216
                classFactory = new ClassFactory(getClassLoader());
7✔
217
            }
218

219
            return classFactory;
5✔
220
        }
221
    }
222

223
    public FieldDeserializer2Factory getFieldDeserializerFactory() {
224
        return fieldDeserializer2Factory;
×
225
    }
226

227
    /**
228
     * Returns the serializer for a class.
229
     *
230
     * @param cl the class of the object that needs to be serialized.
231
     *
232
     * @return a serializer object for the serialization.
233
     */
234
    @Override
235
    public HessianSerializer getSerializer(Class<?> cl) throws HessianProtocolException {
236
        HessianSerializer serializer = cachedSerializerMap.get(cl);
6✔
237

238
        if (serializer != null) {
2✔
239
            return serializer;
2✔
240
        }
241

242
        return cachedSerializerMap.computeIfAbsent(cl, this::loadSerializer);
8✔
243
    }
244

245
    @SneakyThrows
3✔
246
    protected HessianSerializer loadSerializer(Class<?> cl) {
247
        HessianSerializer serializer;
248

249
        for (ISerializerFactory factory : factories) {
7!
250
            serializer = factory.getSerializer(cl);
×
251

252
            if (serializer != null) {
×
253
                return serializer;
×
254
            }
255
        }
×
256

257
        serializer = contextFactory.getSerializer(cl.getName());
6✔
258

259
        if (serializer != null) {
2✔
260
            return serializer;
2✔
261
        }
262

263
        ClassLoader loader = cl.getClassLoader();
3✔
264

265
        if (loader == null) {
2✔
266
            loader = SYSTEM_CLASS_LOADER;
2✔
267
        }
268

269
        ContextSerializerFactory factory = ContextSerializerFactory.create(loader);
3✔
270

271
        serializer = factory.getCustomSerializer(cl);
4✔
272

273
        if (serializer != null) {
2!
274
            return serializer;
×
275
        }
276

277
        if (HessianRemoteObject.class.isAssignableFrom(cl)) {
4!
278
            return new RemoteSerializer();
×
279
        } else if (JavaSerializer.getWriteReplace(cl) != null) {
3✔
280
            HessianSerializer baseSerializer = getDefaultSerializer(cl);
4✔
281

282
            return new WriteReplaceSerializer(cl, getClassLoader(), baseSerializer);
8✔
283
        } else if (Map.class.isAssignableFrom(cl)) {
4✔
284
            if (mapSerializer == null) {
3✔
285
                mapSerializer = new MapSerializer();
5✔
286
            }
287

288
            return mapSerializer;
3✔
289
        } else if (Collection.class.isAssignableFrom(cl)) {
4✔
290
            if (collectionSerializer == null) {
3✔
291
                collectionSerializer = new CollectionSerializer();
5✔
292
            }
293

294
            return collectionSerializer;
3✔
295
        } else if (cl.isArray()) {
3✔
296
            return new ArraySerializer();
4✔
297
        } else if (Throwable.class.isAssignableFrom(cl)) {
4✔
298
            return new ThrowableSerializer(getDefaultSerializer(cl));
7✔
299
        } else if (InputStream.class.isAssignableFrom(cl)) {
4!
300
            return new InputStreamSerializer();
×
301
        } else if (Iterator.class.isAssignableFrom(cl)) {
4!
302
            return IteratorSerializer.create();
×
303
        } else if (Calendar.class.isAssignableFrom(cl)) {
4✔
304
            return CalendarSerializer.SER;
2✔
305
        } else if (Enumeration.class.isAssignableFrom(cl)) {
4✔
306
            return EnumerationSerializer.create();
2✔
307
        } else if (Enum.class.isAssignableFrom(cl)) {
4✔
308
            return new EnumSerializer(cl);
5✔
309
        } else if (Annotation.class.isAssignableFrom(cl)) {
4✔
310
            return new AnnotationSerializer(cl);
5✔
311
        }
312

313
        return getDefaultSerializer(cl);
4✔
314
    }
315

316
    /**
317
     * Returns the default serializer for a class that isn't matched
318
     * directly.  Application can override this method to produce
319
     * bean-style serialization instead of field serialization.
320
     *
321
     * @param cl the class of the object that needs to be serialized.
322
     *
323
     * @return a serializer object for the serialization.
324
     */
325
    protected HessianSerializer getDefaultSerializer(Class<?> cl) {
326
        if (defaultSerializer != null) {
3!
327
            return defaultSerializer;
×
328
        }
329

330
        if (!Serializable.class.isAssignableFrom(cl) && !isAllowNonSerializable) {
7!
331
            throw new IllegalStateException(
3✔
332
                    "Serialized class " + cl.getName() + " must implement java.io.Serializable");
4✔
333
        }
334

335
        if (isEnableUnsafeSerializer && JavaSerializer.getWriteReplace(cl) == null) {
6✔
336
            return UnsafeSerializer.create(cl);
3✔
337
        } else {
338
            return JavaSerializer.create(cl);
3✔
339
        }
340
    }
341

342
    /**
343
     * Returns the deserializer for a class.
344
     *
345
     * @param cl the class of the object that needs to be deserialized.
346
     *
347
     * @return a deserializer object for the serialization.
348
     */
349
    @Override
350
    public HessianDeserializer getDeserializer(Class<?> cl) throws HessianProtocolException {
351
        HessianDeserializer deserializer = cachedDeserializerMap.get(cl);
6✔
352

353
        if (deserializer != null) {
2✔
354
            return deserializer;
2✔
355
        }
356

357
        return cachedDeserializerMap.computeIfAbsent(cl, this::loadDeserializer);
8✔
358
    }
359

360
    @SneakyThrows
3✔
361
    protected HessianDeserializer loadDeserializer(Class<?> cl) {
362
        HessianDeserializer deserializer;
363

364
        for (ISerializerFactory factory : factories) {
7!
365
            deserializer = factory.getDeserializer(cl);
×
366

367
            if (deserializer != null) {
×
368
                return deserializer;
×
369
            }
370
        }
×
371

372
        // XXX: need test
373
        deserializer = contextFactory.getDeserializer(cl.getName());
6✔
374

375
        if (deserializer != null) {
2✔
376
            return deserializer;
2✔
377
        }
378

379
        ContextSerializerFactory factory;
380

381
        if (cl.getClassLoader() != null) {
3✔
382
            factory = ContextSerializerFactory.create(cl.getClassLoader());
5✔
383
        } else {
384
            factory = ContextSerializerFactory.create(SYSTEM_CLASS_LOADER);
3✔
385
        }
386

387
        deserializer = factory.getDeserializer(cl.getName());
5✔
388

389
        if (deserializer != null) {
2!
390
            return deserializer;
×
391
        }
392

393
        deserializer = factory.getCustomDeserializer(cl);
4✔
394

395
        if (deserializer != null) {
2!
396
            return deserializer;
×
397
        }
398

399
        if (Collection.class.isAssignableFrom(cl)) {
4✔
400
            deserializer = new CollectionDeserializer(cl);
6✔
401
        } else if (Map.class.isAssignableFrom(cl)) {
4✔
402
            deserializer = new MapDeserializer(cl);
6✔
403
        } else if (Iterator.class.isAssignableFrom(cl)) {
4!
404
            deserializer = IteratorDeserializer.create();
×
405
        } else if (Annotation.class.isAssignableFrom(cl)) {
4✔
406
            deserializer = new AnnotationDeserializer(cl);
6✔
407
        } else if (cl.isInterface()) {
3!
408
            deserializer = new ObjectDeserializer(cl);
×
409
        } else if (cl.isArray()) {
3✔
410
            deserializer = new ArrayDeserializer(cl.getComponentType());
7✔
411
        } else if (Enumeration.class.isAssignableFrom(cl)) {
4!
412
            deserializer = EnumerationDeserializer.create();
×
413
        } else if (Enum.class.isAssignableFrom(cl)) {
4✔
414
            deserializer = new EnumDeserializer(cl);
6✔
415
        } else if (Class.class.equals(cl)) {
4✔
416
            deserializer = new ClassDeserializer(getClassLoader());
7✔
417
        } else if (java.util.BitSet.class.equals(cl)) {
4✔
418
            deserializer = new BitSetDeserializer(fieldDeserializer2Factory);
7✔
419
        } else if (Calendar.class.isAssignableFrom(cl)) {
4✔
420
            deserializer = new CalendarDeserializer(cl);
6✔
421
        } else {
422
            deserializer = getDefaultDeserializer(cl);
4✔
423
        }
424

425
        return deserializer;
2✔
426
    }
427

428
    /**
429
     * Returns a custom serializer the class
430
     *
431
     * @param cl the class of the object that needs to be serialized.
432
     *
433
     * @return a serializer object for the serialization.
434
     */
435
    protected HessianDeserializer getCustomDeserializer(Class<?> cl) {
436
        try {
437
            Class<?> serClass = Class.forName(cl.getName() + "HessianDeserializer", false, cl.getClassLoader());
×
438

439
            return (HessianDeserializer) serClass.getDeclaredConstructor().newInstance();
×
440
        } catch (ClassNotFoundException e) {
×
441
            log.log(Level.FINEST, e.toString(), e);
×
442

443
            return null;
×
444
        } catch (Exception e) {
×
445
            log.log(Level.FINE, e.toString(), e);
×
446

447
            return null;
×
448
        }
449
    }
450

451
    /**
452
     * Returns the default serializer for a class that isn't matched
453
     * directly.  Application can override this method to produce
454
     * bean-style serialization instead of field serialization.
455
     *
456
     * @param cl the class of the object that needs to be serialized.
457
     *
458
     * @return a serializer object for the serialization.
459
     */
460
    protected HessianDeserializer getDefaultDeserializer(Class<?> cl) {
461
        if (InputStream.class.equals(cl)) {
4!
462
            return InputStreamDeserializer.DESER;
×
463
        }
464

465
        if (isEnableUnsafeSerializer) {
3✔
466
            return new UnsafeDeserializer(cl, fieldDeserializer2Factory);
7✔
467
        } else {
468
            return new JavaDeserializer(cl, fieldDeserializer2Factory);
7✔
469
        }
470
    }
471

472
    /**
473
     * Reads the object as a list.
474
     */
475
    public Object readList(AbstractHessianDecoder in, int length, String type) throws IOException {
476
        HessianDeserializer deserializer = getDeserializer(type);
4✔
477

478
        if (deserializer != null) {
2✔
479
            return deserializer.readList(in, length);
5✔
480
        } else {
481
            return new CollectionDeserializer(ArrayList.class).readList(in, length);
8✔
482
        }
483
    }
484

485
    /**
486
     * Reads the object as a map.
487
     */
488
    public Object readMap(AbstractHessianDecoder in, String type) throws IOException {
489
        HessianDeserializer deserializer = getDeserializer(type);
4✔
490

491
        if (deserializer != null) {
2✔
492
            return deserializer.readMap(in);
4✔
493
        } else if (hashMapDeserializer != null) {
3✔
494
            return hashMapDeserializer.readMap(in);
5✔
495
        } else {
496
            hashMapDeserializer = new MapDeserializer(HashMap.class);
6✔
497

498
            return hashMapDeserializer.readMap(in);
5✔
499
        }
500
    }
501

502
    /**
503
     * Reads the object as a map.
504
     */
505
    public Object readObject(AbstractHessianDecoder in, String type, String[] fieldNames) throws IOException {
506
        HessianDeserializer deserializer = getDeserializer(type);
×
507

508
        if (deserializer != null) {
×
509
            return deserializer.readObject(in, fieldNames);
×
510
        } else if (hashMapDeserializer != null) {
×
511
            return hashMapDeserializer.readObject(in, fieldNames);
×
512
        } else {
513
            hashMapDeserializer = new MapDeserializer(HashMap.class);
×
514

515
            return hashMapDeserializer.readObject(in, fieldNames);
×
516
        }
517
    }
518

519
    /**
520
     * Reads the object as a map.
521
     */
522
    public HessianDeserializer getObjectDeserializer(String type, Class<?> cl) throws HessianProtocolException {
523
        HessianDeserializer reader = getObjectDeserializer(type);
4✔
524

525
        if (cl == null
4✔
526
                || cl.equals(reader.getType())
5✔
527
                || cl.isAssignableFrom(reader.getType())
4✔
528
                || reader.isReadResolve()
4✔
529
                || Hessian2Handle.class.isAssignableFrom(reader.getType())) {
3!
530
            return reader;
2✔
531
        }
532

533
        if (log.isLoggable(Level.FINE)) {
4!
534
            log.fine("hessian: expected deserializer '" + cl.getName() + "' at '" + type + "' ("
×
535
                    + reader.getType().getName() + ")");
×
536
        }
537

538
        return getDeserializer(cl);
4✔
539
    }
540

541
    /**
542
     * Reads the object as a map.
543
     */
544
    public HessianDeserializer getObjectDeserializer(String type) throws HessianProtocolException {
545
        HessianDeserializer deserializer = getDeserializer(type);
4✔
546

547
        if (deserializer != null) {
2✔
548
            return deserializer;
2✔
549
        } else if (hashMapDeserializer != null) {
3!
550
            return hashMapDeserializer;
3✔
551
        } else {
552
            hashMapDeserializer = new MapDeserializer(HashMap.class);
×
553

554
            return hashMapDeserializer;
×
555
        }
556
    }
557

558
    /**
559
     * Reads the object as a map.
560
     */
561
    public HessianDeserializer getListDeserializer(String type, Class<?> cl) throws HessianProtocolException {
562
        HessianDeserializer reader = getListDeserializer(type);
4✔
563

564
        if (cl == null || cl.equals(reader.getType()) || cl.isAssignableFrom(reader.getType())) {
12✔
565
            return reader;
2✔
566
        }
567

568
        if (log.isLoggable(Level.FINE)) {
4!
569
            log.fine("hessian: expected '" + cl.getName() + "' at '" + type + "' ("
×
570
                    + reader.getType().getName() + ")");
×
571
        }
572

573
        return getDeserializer(cl);
4✔
574
    }
575

576
    /**
577
     * Reads the object as a map.
578
     */
579
    public HessianDeserializer getListDeserializer(String type) throws HessianProtocolException {
580
        HessianDeserializer deserializer = getDeserializer(type);
4✔
581

582
        if (deserializer != null) {
2✔
583
            return deserializer;
2✔
584
        } else if (arrayListDeserializer != null) {
3✔
585
            return arrayListDeserializer;
3✔
586
        } else {
587
            arrayListDeserializer = new CollectionDeserializer(ArrayList.class);
6✔
588

589
            return arrayListDeserializer;
3✔
590
        }
591
    }
592

593
    /**
594
     * Returns a deserializer based on a string type.
595
     */
596
    public HessianDeserializer getDeserializer(String type) throws HessianProtocolException {
597
        if (type == null || type.isEmpty()) {
5!
598
            return null;
2✔
599
        }
600

601
        HessianDeserializer deserializer = cachedTypeDeserializerMap.get(type);
6✔
602

603
        if (deserializer != null) {
2✔
604
            return deserializer;
2✔
605
        }
606

607
        deserializer = STATIC_TYPE_MAP.get(type);
5✔
608
        if (deserializer != null) {
2✔
609
            return deserializer;
2✔
610
        }
611

612
        if (type.startsWith("[")) {
4✔
613
            HessianDeserializer subDeserializer = getDeserializer(type.substring(1));
6✔
614

615
            if (subDeserializer != null) {
2✔
616
                deserializer = new ArrayDeserializer(subDeserializer.getType());
7✔
617
            } else {
618
                deserializer = new ArrayDeserializer(Object.class);
5✔
619
            }
620
        } else {
1✔
621
            try {
622
                Class<?> cl = loadSerializedClass(type);
4✔
623

624
                deserializer = getDeserializer(cl);
4✔
625
            } catch (Exception e) {
1✔
626
                log.warning("Hessian2: '" + type + "' is an unknown class in " + getClassLoader() + ":\n" + e);
9✔
627

628
                log.log(Level.FINER, e.toString(), e);
6✔
629
            }
1✔
630
        }
631

632
        if (deserializer != null) {
2✔
633
            cachedTypeDeserializerMap.putIfAbsent(type, deserializer);
6✔
634
        }
635

636
        return deserializer;
2✔
637
    }
638

639
    private static void addBasic(String typeName, int type) {
640
        HessianDeserializer deserializer = new BasicDeserializer(type);
5✔
641

642
        STATIC_TYPE_MAP.put(typeName, deserializer);
5✔
643
    }
1✔
644

645
    static {
646
        STATIC_TYPE_MAP = new HashMap<>();
4✔
647

648
        addBasic("void", BasicSerializer.NULL);
3✔
649

650
        addBasic("boolean", BasicSerializer.BOOLEAN);
3✔
651
        addBasic("byte", BasicSerializer.BYTE);
3✔
652
        addBasic("short", BasicSerializer.SHORT);
3✔
653
        addBasic("int", BasicSerializer.INTEGER);
3✔
654
        addBasic("long", BasicSerializer.LONG);
3✔
655
        addBasic("float", BasicSerializer.FLOAT);
3✔
656
        addBasic("double", BasicSerializer.DOUBLE);
3✔
657
        addBasic("char", BasicSerializer.CHARACTER_OBJECT);
3✔
658
        addBasic("string", BasicSerializer.STRING);
3✔
659
        addBasic("string", BasicSerializer.STRING_BUILDER);
3✔
660
        addBasic("object", BasicSerializer.OBJECT);
3✔
661
        addBasic("date", BasicSerializer.DATE);
3✔
662

663
        addBasic("boolean", BasicSerializer.BOOLEAN);
3✔
664
        addBasic("byte", BasicSerializer.BYTE);
3✔
665
        addBasic("short", BasicSerializer.SHORT);
3✔
666
        addBasic("int", BasicSerializer.INTEGER);
3✔
667
        addBasic("long", BasicSerializer.LONG);
3✔
668
        addBasic("float", BasicSerializer.FLOAT);
3✔
669
        addBasic("double", BasicSerializer.DOUBLE);
3✔
670
        addBasic("char", BasicSerializer.CHARACTER);
3✔
671

672
        addBasic("[boolean", BasicSerializer.BOOLEAN_ARRAY);
3✔
673
        addBasic("[byte", BasicSerializer.BYTE_ARRAY);
3✔
674
        addBasic("[short", BasicSerializer.SHORT_ARRAY);
3✔
675
        addBasic("[int", BasicSerializer.INTEGER_ARRAY);
3✔
676
        addBasic("[long", BasicSerializer.LONG_ARRAY);
3✔
677
        addBasic("[float", BasicSerializer.FLOAT_ARRAY);
3✔
678
        addBasic("[double", BasicSerializer.DOUBLE_ARRAY);
3✔
679
        addBasic("[char", BasicSerializer.CHARACTER_ARRAY);
3✔
680
        addBasic("[string", BasicSerializer.STRING_ARRAY);
3✔
681
        addBasic("[object", BasicSerializer.OBJECT_ARRAY);
3✔
682

683
        HessianDeserializer objectDeserializer = new JavaDeserializer(Object.class, new FieldDeserializer2Factory());
8✔
684
        STATIC_TYPE_MAP.put("object", objectDeserializer);
5✔
685
        STATIC_TYPE_MAP.put(HessianRemote.class.getName(), RemoteDeserializer.DESER);
6✔
686

687
        SYSTEM_CLASS_LOADER = ClassLoader.getSystemClassLoader();
2✔
688
    }
1✔
689
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc