-
Notifications
You must be signed in to change notification settings - Fork 94
/
AbstractItem.java
80 lines (67 loc) · 2.14 KB
/
AbstractItem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Copyright (c) 2016, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
package org.eclipse.yasson.internal.serializer;
import java.lang.reflect.Type;
import org.eclipse.yasson.internal.model.ClassModel;
/**
* Metadata wrapper for currently processed object.
* References mapping models of an unmarshalled item,
* creates instances of it, sets finished unmarshalled objects into object tree.
*
* @param <T> Instantiated object type
*/
public abstract class AbstractItem<T> implements CurrentItem<T> {
/**
* Item containing instance of wrapping object and its metadata.
* Null in case of a root object.
*/
private final CurrentItem<?> wrapper;
private final Type runtimeType;
/**
* Cached reference to mapping model of an item.
*/
private final ClassModel classModel;
/**
* Creates and populates an instance from given builder.
*
* @param builder Builder to initialize from.
*/
protected AbstractItem(AbstractSerializerBuilder builder) {
this.wrapper = builder.getWrapper();
this.classModel = builder.getClassModel();
this.runtimeType = builder.getRuntimeType();
}
/**
* Creates an instance.
*
* @param wrapper Item wrapper.
* @param runtimeType Runtime type.
* @param classModel Class model.
*/
public AbstractItem(CurrentItem<?> wrapper, Type runtimeType, ClassModel classModel) {
this.wrapper = wrapper;
this.runtimeType = runtimeType;
this.classModel = classModel;
}
@Override
public ClassModel getClassModel() {
return classModel;
}
@Override
public CurrentItem<?> getWrapper() {
return wrapper;
}
@Override
public Type getRuntimeType() {
return runtimeType;
}
}