Class SimpleEntryFactory

java.lang.Object
com.cedarsoftware.io.factory.SimpleEntryFactory
All Implemented Interfaces:
ClassFactory

public class SimpleEntryFactory extends Object implements ClassFactory
Factory class to create AbstractMap.SimpleEntry and AbstractMap.SimpleImmutableEntry instances.

These classes have final fields that cannot be set via reflection on Java 9+, so we must use the constructor to create properly initialized instances.

Handles both:

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.
  • Constructor Details

    • SimpleEntryFactory

      public SimpleEntryFactory()
  • Method Details

    • newInstance

      public Object newInstance(Class<?> c, JsonObject jObj, Resolver resolver)
      Creates a new SimpleEntry or SimpleImmutableEntry instance using values from the JsonObject.
      Specified by:
      newInstance in interface ClassFactory
      Parameters:
      c - The class to instantiate (SimpleEntry or SimpleImmutableEntry)
      jObj - The JsonObject containing "key" and "value" fields
      resolver - The resolver for converting nested objects
      Returns:
      A new entry instance with the key and value set
    • isObjectFinal

      public boolean isObjectFinal()
      Returns true because the entry is fully constructed by this factory. No further field processing is needed.
      Specified by:
      isObjectFinal in interface ClassFactory
      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.