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

wuwen5 / hessian / 17190932491

24 Aug 2025 03:32PM UTC coverage: 68.598% (+0.2%) from 68.416%
17190932491

push

github

wuwen5
Bump actions/checkout from 4 to 5

Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

1793 of 2809 branches covered (63.83%)

Branch coverage included in aggregate %.

4173 of 5888 relevant lines covered (70.87%)

3.08 hits per line

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

80.27
hessian2-codec/src/main/java/io/github/wuwen5/hessian/io/SerializerFactory.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.net.InetAddress;
59
import java.util.ArrayList;
60
import java.util.Calendar;
61
import java.util.Collection;
62
import java.util.Enumeration;
63
import java.util.HashMap;
64
import java.util.Iterator;
65
import java.util.List;
66
import java.util.Map;
67
import java.util.WeakHashMap;
68
import java.util.concurrent.ConcurrentHashMap;
69
import java.util.concurrent.ConcurrentMap;
70
import java.util.logging.Level;
71
import java.util.logging.Logger;
72
import lombok.SneakyThrows;
73

74
/**
75
 * Factory for returning serialization methods.
76
 */
77
public class SerializerFactory extends AbstractSerializerFactory {
78
    private static final Logger log = Logger.getLogger(SerializerFactory.class.getName());
4✔
79

80
    private static final ClassLoader SYSTEM_CLASS_LOADER;
81

82
    private static final Map<String, Deserializer> STATIC_TYPE_MAP;
83

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

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

90
    protected Serializer defaultSerializer;
91

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

97
    protected CollectionSerializer collectionSerializer;
98
    protected MapSerializer mapSerializer;
99

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

106
    private boolean isAllowNonSerializable;
107
    private final boolean isEnableUnsafeSerializer = (UnsafeSerializer.isEnabled() && UnsafeDeserializer.isEnabled());
9!
108

109
    private final FieldDeserializer2Factory fieldDeserializer2Factory;
110

111
    private ClassFactory classFactory;
112

113
    public SerializerFactory() {
114
        this(Thread.currentThread().getContextClassLoader());
4✔
115
    }
1✔
116

117
    public SerializerFactory(ClassLoader loader) {
2✔
118
        loaderRef = new WeakReference<>(loader);
6✔
119

120
        contextFactory = ContextSerializerFactory.create(loader);
4✔
121

122
        if (isEnableUnsafeSerializer) {
3✔
123
            fieldDeserializer2Factory = new FieldDeserializer2FactoryUnsafe();
6✔
124
        } else {
125
            fieldDeserializer2Factory = new FieldDeserializer2Factory();
5✔
126
        }
127
    }
1✔
128

129
    public static SerializerFactory createDefault() {
130
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
3✔
131

132
        synchronized (DEFAULT_FACTORY_REF_MAP) {
4✔
133
            SoftReference<SerializerFactory> factoryRef = DEFAULT_FACTORY_REF_MAP.get(loader);
5✔
134

135
            SerializerFactory factory = null;
2✔
136

137
            if (factoryRef != null) {
2✔
138
                factory = factoryRef.get();
4✔
139
            }
140

141
            if (factory == null) {
2✔
142
                factory = new SerializerFactory();
4✔
143

144
                factoryRef = new SoftReference<>(factory);
5✔
145

146
                DEFAULT_FACTORY_REF_MAP.put(loader, factoryRef);
5✔
147
            }
148

149
            return factory;
4✔
150
        }
151
    }
152

153
    public ClassLoader getClassLoader() {
154
        return loaderRef.get();
5✔
155
    }
156

157
    /**
158
     * Set true if the collection serializer should send the java type.
159
     */
160
    public void setSendCollectionType(boolean isSendType) {
161
        if (collectionSerializer == null) {
×
162
            collectionSerializer = new CollectionSerializer();
×
163
        }
164

165
        collectionSerializer.setSendJavaType(isSendType);
×
166

167
        if (mapSerializer == null) {
×
168
            mapSerializer = new MapSerializer();
×
169
        }
170

171
        mapSerializer.setSendJavaType(isSendType);
×
172
    }
×
173

174
    /**
175
     * Adds a factory.
176
     */
177
    public void addFactory(AbstractSerializerFactory factory) {
178
        factories.add(factory);
×
179
    }
×
180

181
    /**
182
     * If true, non-serializable objects are allowed.
183
     */
184
    public void setAllowNonSerializable(boolean allow) {
185
        isAllowNonSerializable = allow;
×
186
    }
×
187

188
    /**
189
     * If true, non-serializable objects are allowed.
190
     */
191
    public boolean isAllowNonSerializable() {
192
        return isAllowNonSerializable;
×
193
    }
194

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

205
        if (serializer instanceof ObjectSerializer) {
3✔
206
            return ((ObjectSerializer) serializer).getObjectSerializer();
4✔
207
        } else {
208
            return serializer;
2✔
209
        }
210
    }
211

212
    public Class<?> loadSerializedClass(String className) throws ClassNotFoundException {
213
        return getClassFactory().load(className);
5✔
214
    }
215

216
    public ClassFactory getClassFactory() {
217
        synchronized (this) {
4✔
218
            if (classFactory == null) {
3✔
219
                classFactory = new ClassFactory(getClassLoader());
7✔
220
            }
221

222
            return classFactory;
5✔
223
        }
224
    }
225

226
    public FieldDeserializer2Factory getFieldDeserializerFactory() {
227
        return fieldDeserializer2Factory;
×
228
    }
229

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

241
        if (serializer != null) {
2✔
242
            return serializer;
2✔
243
        }
244

245
        return cachedSerializerMap.computeIfAbsent(cl, this::loadSerializer);
8✔
246
    }
247

248
    @SneakyThrows
3✔
249
    protected Serializer loadSerializer(Class<?> cl) {
250
        Serializer serializer;
251

252
        for (int i = 0; factories != null && i < factories.size(); i++) {
10!
253
            AbstractSerializerFactory factory = factories.get(i);
×
254

255
            serializer = factory.getSerializer(cl);
×
256

257
            if (serializer != null) {
×
258
                return serializer;
×
259
            }
260
        }
261

262
        serializer = contextFactory.getSerializer(cl.getName());
6✔
263

264
        if (serializer != null) {
2✔
265
            return serializer;
2✔
266
        }
267

268
        ClassLoader loader = cl.getClassLoader();
3✔
269

270
        if (loader == null) {
2✔
271
            loader = SYSTEM_CLASS_LOADER;
2✔
272
        }
273

274
        ContextSerializerFactory factory = ContextSerializerFactory.create(loader);
3✔
275

276
        serializer = factory.getCustomSerializer(cl);
4✔
277

278
        if (serializer != null) {
2!
279
            return serializer;
×
280
        }
281

282
        if (HessianRemoteObject.class.isAssignableFrom(cl)) {
4!
283
            return new RemoteSerializer();
×
284
        } // TODO
285
        //    else if (BurlapRemoteObject.class.isAssignableFrom(cl)) {
286
        //      return new RemoteSerializer();
287
        //    }
288
        else if (InetAddress.class.isAssignableFrom(cl)) {
4!
289
            return InetAddressSerializer.create();
×
290
        } else if (JavaSerializer.getWriteReplace(cl) != null) {
3✔
291
            Serializer baseSerializer = getDefaultSerializer(cl);
4✔
292

293
            return new WriteReplaceSerializer(cl, getClassLoader(), baseSerializer);
8✔
294
        } else if (Map.class.isAssignableFrom(cl)) {
4✔
295
            if (mapSerializer == null) {
3✔
296
                mapSerializer = new MapSerializer();
5✔
297
            }
298

299
            return mapSerializer;
3✔
300
        } else if (Collection.class.isAssignableFrom(cl)) {
4✔
301
            if (collectionSerializer == null) {
3✔
302
                collectionSerializer = new CollectionSerializer();
5✔
303
            }
304

305
            return collectionSerializer;
3✔
306
        } else if (cl.isArray()) {
3✔
307
            return new ArraySerializer();
4✔
308
        } else if (Throwable.class.isAssignableFrom(cl)) {
4✔
309
            return new ThrowableSerializer(getDefaultSerializer(cl));
7✔
310
        } else if (InputStream.class.isAssignableFrom(cl)) {
4!
311
            return new InputStreamSerializer();
×
312
        } else if (Iterator.class.isAssignableFrom(cl)) {
4!
313
            return IteratorSerializer.create();
×
314
        } else if (Calendar.class.isAssignableFrom(cl)) {
4✔
315
            return CalendarSerializer.SER;
2✔
316
        } else if (Enumeration.class.isAssignableFrom(cl)) {
4✔
317
            return EnumerationSerializer.create();
2✔
318
        } else if (Enum.class.isAssignableFrom(cl)) {
4✔
319
            return new EnumSerializer(cl);
5✔
320
        } else if (Annotation.class.isAssignableFrom(cl)) {
4✔
321
            return new AnnotationSerializer(cl);
5✔
322
        }
323

324
        return getDefaultSerializer(cl);
4✔
325
    }
326

327
    /**
328
     * Returns the default serializer for a class that isn't matched
329
     * directly.  Application can override this method to produce
330
     * bean-style serialization instead of field serialization.
331
     *
332
     * @param cl the class of the object that needs to be serialized.
333
     *
334
     * @return a serializer object for the serialization.
335
     */
336
    protected Serializer getDefaultSerializer(Class<?> cl) {
337
        if (defaultSerializer != null) {
3!
338
            return defaultSerializer;
×
339
        }
340

341
        if (!Serializable.class.isAssignableFrom(cl) && !isAllowNonSerializable) {
7!
342
            throw new IllegalStateException(
3✔
343
                    "Serialized class " + cl.getName() + " must implement java.io.Serializable");
4✔
344
        }
345

346
        if (isEnableUnsafeSerializer && JavaSerializer.getWriteReplace(cl) == null) {
6✔
347
            return UnsafeSerializer.create(cl);
3✔
348
        } else {
349
            return JavaSerializer.create(cl);
3✔
350
        }
351
    }
352

353
    /**
354
     * Returns the deserializer for a class.
355
     *
356
     * @param cl the class of the object that needs to be deserialized.
357
     *
358
     * @return a deserializer object for the serialization.
359
     */
360
    @Override
361
    public Deserializer getDeserializer(Class<?> cl) throws HessianProtocolException {
362
        Deserializer deserializer = cachedDeserializerMap.get(cl);
6✔
363

364
        if (deserializer != null) {
2✔
365
            return deserializer;
2✔
366
        }
367

368
        return cachedDeserializerMap.computeIfAbsent(cl, this::loadDeserializer);
8✔
369
    }
370

371
    @SneakyThrows
3✔
372
    protected Deserializer loadDeserializer(Class<?> cl) {
373
        Deserializer deserializer = null;
2✔
374

375
        for (int i = 0; deserializer == null && factories != null && i < factories.size(); i++) {
12!
376
            AbstractSerializerFactory factory = factories.get(i);
×
377

378
            deserializer = factory.getDeserializer(cl);
×
379
        }
380

381
        if (deserializer != null) {
2!
382
            return deserializer;
×
383
        }
384

385
        // XXX: need test
386
        deserializer = contextFactory.getDeserializer(cl.getName());
6✔
387

388
        if (deserializer != null) {
2✔
389
            return deserializer;
2✔
390
        }
391

392
        ContextSerializerFactory factory;
393

394
        if (cl.getClassLoader() != null) {
3✔
395
            factory = ContextSerializerFactory.create(cl.getClassLoader());
5✔
396
        } else {
397
            factory = ContextSerializerFactory.create(SYSTEM_CLASS_LOADER);
3✔
398
        }
399

400
        deserializer = factory.getDeserializer(cl.getName());
5✔
401

402
        if (deserializer != null) {
2!
403
            return deserializer;
×
404
        }
405

406
        deserializer = factory.getCustomDeserializer(cl);
4✔
407

408
        if (deserializer != null) {
2!
409
            return deserializer;
×
410
        }
411

412
        if (Collection.class.isAssignableFrom(cl)) {
4✔
413
            deserializer = new CollectionDeserializer(cl);
6✔
414
        } else if (Map.class.isAssignableFrom(cl)) {
4✔
415
            deserializer = new MapDeserializer(cl);
6✔
416
        } else if (Iterator.class.isAssignableFrom(cl)) {
4!
417
            deserializer = IteratorDeserializer.create();
×
418
        } else if (Annotation.class.isAssignableFrom(cl)) {
4✔
419
            deserializer = new AnnotationDeserializer(cl);
6✔
420
        } else if (cl.isInterface()) {
3!
421
            deserializer = new ObjectDeserializer(cl);
×
422
        } else if (cl.isArray()) {
3✔
423
            deserializer = new ArrayDeserializer(cl.getComponentType());
7✔
424
        } else if (Enumeration.class.isAssignableFrom(cl)) {
4!
425
            deserializer = EnumerationDeserializer.create();
×
426
        } else if (Enum.class.isAssignableFrom(cl)) {
4✔
427
            deserializer = new EnumDeserializer(cl);
6✔
428
        } else if (Class.class.equals(cl)) {
4✔
429
            deserializer = new ClassDeserializer(getClassLoader());
7✔
430
        } else if (java.util.BitSet.class.equals(cl)) {
4✔
431
            deserializer = new BitSetDeserializer(fieldDeserializer2Factory);
7✔
432
        } else {
433
            deserializer = getDefaultDeserializer(cl);
4✔
434
        }
435

436
        return deserializer;
2✔
437
    }
438

439
    /**
440
     * Returns a custom serializer the class
441
     *
442
     * @param cl the class of the object that needs to be serialized.
443
     *
444
     * @return a serializer object for the serialization.
445
     */
446
    protected Deserializer getCustomDeserializer(Class<?> cl) {
447
        try {
448
            Class<?> serClass = Class.forName(cl.getName() + "HessianDeserializer", false, cl.getClassLoader());
×
449

450
            return (Deserializer) serClass.getDeclaredConstructor().newInstance();
×
451
        } catch (ClassNotFoundException e) {
×
452
            log.log(Level.FINEST, e.toString(), e);
×
453

454
            return null;
×
455
        } catch (Exception e) {
×
456
            log.log(Level.FINE, e.toString(), e);
×
457

458
            return null;
×
459
        }
460
    }
461

462
    /**
463
     * Returns the default serializer for a class that isn't matched
464
     * directly.  Application can override this method to produce
465
     * bean-style serialization instead of field serialization.
466
     *
467
     * @param cl the class of the object that needs to be serialized.
468
     *
469
     * @return a serializer object for the serialization.
470
     */
471
    protected Deserializer getDefaultDeserializer(Class<?> cl) {
472
        if (InputStream.class.equals(cl)) {
4!
473
            return InputStreamDeserializer.DESER;
×
474
        }
475

476
        if (isEnableUnsafeSerializer) {
3✔
477
            return new UnsafeDeserializer(cl, fieldDeserializer2Factory);
7✔
478
        } else {
479
            return new JavaDeserializer(cl, fieldDeserializer2Factory);
7✔
480
        }
481
    }
482

483
    /**
484
     * Reads the object as a list.
485
     */
486
    public Object readList(AbstractHessianDecoder in, int length, String type) throws IOException {
487
        Deserializer deserializer = getDeserializer(type);
4✔
488

489
        if (deserializer != null) {
2✔
490
            return deserializer.readList(in, length);
5✔
491
        } else {
492
            return new CollectionDeserializer(ArrayList.class).readList(in, length);
8✔
493
        }
494
    }
495

496
    /**
497
     * Reads the object as a map.
498
     */
499
    public Object readMap(AbstractHessianDecoder in, String type) throws IOException {
500
        Deserializer deserializer = getDeserializer(type);
4✔
501

502
        if (deserializer != null) {
2✔
503
            return deserializer.readMap(in);
4✔
504
        } else if (hashMapDeserializer != null) {
3!
505
            return hashMapDeserializer.readMap(in);
5✔
506
        } else {
507
            hashMapDeserializer = new MapDeserializer(HashMap.class);
×
508

509
            return hashMapDeserializer.readMap(in);
×
510
        }
511
    }
512

513
    /**
514
     * Reads the object as a map.
515
     */
516
    public Object readObject(AbstractHessianDecoder in, String type, String[] fieldNames) throws IOException {
517
        Deserializer deserializer = getDeserializer(type);
×
518

519
        if (deserializer != null) {
×
520
            return deserializer.readObject(in, fieldNames);
×
521
        } else if (hashMapDeserializer != null) {
×
522
            return hashMapDeserializer.readObject(in, fieldNames);
×
523
        } else {
524
            hashMapDeserializer = new MapDeserializer(HashMap.class);
×
525

526
            return hashMapDeserializer.readObject(in, fieldNames);
×
527
        }
528
    }
529

530
    /**
531
     * Reads the object as a map.
532
     */
533
    public Deserializer getObjectDeserializer(String type, Class<?> cl) throws HessianProtocolException {
534
        Deserializer reader = getObjectDeserializer(type);
4✔
535

536
        if (cl == null
4✔
537
                || cl.equals(reader.getType())
5✔
538
                || cl.isAssignableFrom(reader.getType())
4✔
539
                || reader.isReadResolve()
4✔
540
                || HessianHandle.class.isAssignableFrom(reader.getType())) {
3!
541
            return reader;
2✔
542
        }
543

544
        if (log.isLoggable(Level.FINE)) {
4!
545
            log.fine("hessian: expected deserializer '" + cl.getName() + "' at '" + type + "' ("
×
546
                    + reader.getType().getName() + ")");
×
547
        }
548

549
        return getDeserializer(cl);
4✔
550
    }
551

552
    /**
553
     * Reads the object as a map.
554
     */
555
    public Deserializer getObjectDeserializer(String type) throws HessianProtocolException {
556
        Deserializer deserializer = getDeserializer(type);
4✔
557

558
        if (deserializer != null) {
2✔
559
            return deserializer;
2✔
560
        } else if (hashMapDeserializer != null) {
3✔
561
            return hashMapDeserializer;
3✔
562
        } else {
563
            hashMapDeserializer = new MapDeserializer(HashMap.class);
6✔
564

565
            return hashMapDeserializer;
3✔
566
        }
567
    }
568

569
    /**
570
     * Reads the object as a map.
571
     */
572
    public Deserializer getListDeserializer(String type, Class<?> cl) throws HessianProtocolException {
573
        Deserializer reader = getListDeserializer(type);
4✔
574

575
        if (cl == null || cl.equals(reader.getType()) || cl.isAssignableFrom(reader.getType())) {
12✔
576
            return reader;
2✔
577
        }
578

579
        if (log.isLoggable(Level.FINE)) {
4!
580
            log.fine("hessian: expected '" + cl.getName() + "' at '" + type + "' ("
×
581
                    + reader.getType().getName() + ")");
×
582
        }
583

584
        return getDeserializer(cl);
4✔
585
    }
586

587
    /**
588
     * Reads the object as a map.
589
     */
590
    public Deserializer getListDeserializer(String type) throws HessianProtocolException {
591
        Deserializer deserializer = getDeserializer(type);
4✔
592

593
        if (deserializer != null) {
2✔
594
            return deserializer;
2✔
595
        } else if (arrayListDeserializer != null) {
3✔
596
            return arrayListDeserializer;
3✔
597
        } else {
598
            arrayListDeserializer = new CollectionDeserializer(ArrayList.class);
6✔
599

600
            return arrayListDeserializer;
3✔
601
        }
602
    }
603

604
    /**
605
     * Returns a deserializer based on a string type.
606
     */
607
    public Deserializer getDeserializer(String type) throws HessianProtocolException {
608
        if (type == null || type.isEmpty()) {
5!
609
            return null;
2✔
610
        }
611

612
        Deserializer deserializer = cachedTypeDeserializerMap.get(type);
6✔
613

614
        if (deserializer != null) {
2✔
615
            return deserializer;
2✔
616
        }
617

618
        deserializer = STATIC_TYPE_MAP.get(type);
5✔
619
        if (deserializer != null) {
2✔
620
            return deserializer;
2✔
621
        }
622

623
        if (type.startsWith("[")) {
4✔
624
            Deserializer subDeserializer = getDeserializer(type.substring(1));
6✔
625

626
            if (subDeserializer != null) {
2✔
627
                deserializer = new ArrayDeserializer(subDeserializer.getType());
7✔
628
            } else {
629
                deserializer = new ArrayDeserializer(Object.class);
5✔
630
            }
631
        } else {
1✔
632
            try {
633
                Class<?> cl = loadSerializedClass(type);
4✔
634

635
                deserializer = getDeserializer(cl);
4✔
636
            } catch (Exception e) {
1✔
637
                log.warning("Hessian/Burlap: '" + type + "' is an unknown class in " + getClassLoader() + ":\n" + e);
9✔
638

639
                log.log(Level.FINER, e.toString(), e);
6✔
640
            }
1✔
641
        }
642

643
        if (deserializer != null) {
2✔
644
            cachedTypeDeserializerMap.putIfAbsent(type, deserializer);
6✔
645
        }
646

647
        return deserializer;
2✔
648
    }
649

650
    private static void addBasic(Class<?> cl, String typeName, int type) {
651
        Deserializer deserializer = new BasicDeserializer(type);
5✔
652

653
        STATIC_TYPE_MAP.put(typeName, deserializer);
5✔
654
    }
1✔
655

656
    static {
657
        STATIC_TYPE_MAP = new HashMap<>();
4✔
658

659
        addBasic(void.class, "void", BasicSerializer.NULL);
4✔
660

661
        addBasic(Boolean.class, "boolean", BasicSerializer.BOOLEAN);
4✔
662
        addBasic(Byte.class, "byte", BasicSerializer.BYTE);
4✔
663
        addBasic(Short.class, "short", BasicSerializer.SHORT);
4✔
664
        addBasic(Integer.class, "int", BasicSerializer.INTEGER);
4✔
665
        addBasic(Long.class, "long", BasicSerializer.LONG);
4✔
666
        addBasic(Float.class, "float", BasicSerializer.FLOAT);
4✔
667
        addBasic(Double.class, "double", BasicSerializer.DOUBLE);
4✔
668
        addBasic(Character.class, "char", BasicSerializer.CHARACTER_OBJECT);
4✔
669
        addBasic(String.class, "string", BasicSerializer.STRING);
4✔
670
        addBasic(StringBuilder.class, "string", BasicSerializer.STRING_BUILDER);
4✔
671
        addBasic(Object.class, "object", BasicSerializer.OBJECT);
4✔
672
        addBasic(java.util.Date.class, "date", BasicSerializer.DATE);
4✔
673

674
        addBasic(boolean.class, "boolean", BasicSerializer.BOOLEAN);
4✔
675
        addBasic(byte.class, "byte", BasicSerializer.BYTE);
4✔
676
        addBasic(short.class, "short", BasicSerializer.SHORT);
4✔
677
        addBasic(int.class, "int", BasicSerializer.INTEGER);
4✔
678
        addBasic(long.class, "long", BasicSerializer.LONG);
4✔
679
        addBasic(float.class, "float", BasicSerializer.FLOAT);
4✔
680
        addBasic(double.class, "double", BasicSerializer.DOUBLE);
4✔
681
        addBasic(char.class, "char", BasicSerializer.CHARACTER);
4✔
682

683
        addBasic(boolean[].class, "[boolean", BasicSerializer.BOOLEAN_ARRAY);
4✔
684
        addBasic(byte[].class, "[byte", BasicSerializer.BYTE_ARRAY);
4✔
685
        addBasic(short[].class, "[short", BasicSerializer.SHORT_ARRAY);
4✔
686
        addBasic(int[].class, "[int", BasicSerializer.INTEGER_ARRAY);
4✔
687
        addBasic(long[].class, "[long", BasicSerializer.LONG_ARRAY);
4✔
688
        addBasic(float[].class, "[float", BasicSerializer.FLOAT_ARRAY);
4✔
689
        addBasic(double[].class, "[double", BasicSerializer.DOUBLE_ARRAY);
4✔
690
        addBasic(char[].class, "[char", BasicSerializer.CHARACTER_ARRAY);
4✔
691
        addBasic(String[].class, "[string", BasicSerializer.STRING_ARRAY);
4✔
692
        addBasic(Object[].class, "[object", BasicSerializer.OBJECT_ARRAY);
4✔
693

694
        Deserializer objectDeserializer = new JavaDeserializer(Object.class, new FieldDeserializer2Factory());
8✔
695
        STATIC_TYPE_MAP.put("object", objectDeserializer);
5✔
696
        STATIC_TYPE_MAP.put(HessianRemote.class.getName(), RemoteDeserializer.DESER);
6✔
697

698
        ClassLoader systemClassLoader = null;
2✔
699
        try {
700
            systemClassLoader = ClassLoader.getSystemClassLoader();
2✔
701
        } catch (Exception ignored) {
×
702
        }
1✔
703

704
        SYSTEM_CLASS_LOADER = systemClassLoader;
2✔
705
    }
1✔
706
}
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