Package com.cedarsoftware.io
Interface ClassFactory
- All Known Subinterfaces:
JsonReader.ClassFactory
- All Known Implementing Classes:
ArrayFactory,AtomicIntegerArrayFactory,AtomicLongArrayFactory,BitSetFactory,CharacterPrimArrayFactory,CheckedFactory,CollectionFactory,CompactMapFactory,CompactSetFactory,CountDownLatchFactory,EmptyFactory,EnumClassFactory,EnumSetFactory,MapFactory,MultiKeyMapFactory,OptionalFactory,RecordFactory,ReentrantLockFactory,ReentrantReadWriteLockFactory,SemaphoreFactory,SimpleEntryFactory,SingletonFactory,StackTraceElementFactory,SynchronizedFactory,ThrowableFactory,UnmodifiableFactory
public interface ClassFactory
Implement this interface to create custom instances of classes during JSON deserialization.
Your factory will be called when json-io encounters an instance of a class you register
with
ReadOptionsBuilder.addClassFactory(Class, ClassFactory).
Use the passed in JsonObject to source values for constructing your class instance.
This is useful for classes that require special construction logic, such as immutable objects,
classes with private constructors, or classes that need specific initialization.
- Author:
- John DeRegnaucourt (jdereg@gmail.com)
Copyright (c) Cedar Software LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
License
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleandefault ObjectnewInstance(Class<?> c, JsonObject jObj, Resolver resolver) Implement this method to return a new instance of the passed in Class.
-
Method Details
-
newInstance
Implement this method to return a new instance of the passed in Class. Use the passed in JsonObject to supply values to the construction of the object.- Parameters:
c- Class of the object that needs to be createdjObj- JsonObject containing the JSON data (if primitive type use jObj.getValue())resolver- Resolver instance that has references to ID Map, Converter, ReadOptions- Returns:
- a new instance of the class. If you fill the new instance using the value(s)
from the JsonObject and no further work is needed for construction, then
override the
isObjectFinal()method and return true.
-
isObjectFinal
default boolean isObjectFinal()- Returns:
- true if this object is instantiated and completely filled using the contents from the JsonObject. In this case, no further processing will be performed on the instance. If the object has sub-objects (complex fields), then return false so that json-io will continue filling out the remaining portion of the object.
-