Package org.instancio

Class Bindings


  • public class Bindings
    extends Object
    A collection of static factory methods for creating Bindings.BindingImpls.

    A binding allows targeting a specific class or field.

    Examples:

    • field(Example.class, "someField") - target some field of Example class
    • all(Example.class) - target all instances of Example class
    • of(Binding...) - convenience method for targeting multiple bindings
    • allStrings() - target all Strings
    • allInts() - target all Integer objects and int primitives
    • Method Detail

      • field

        public static Binding field​(Class<?> declaringClass,
                                    String fieldName)
        Creates a binding for the given class's field.
        Parameters:
        declaringClass - class declaring the field
        fieldName - field name to bind
        Returns:
        binding
      • field

        public static Binding field​(String fieldName)
        Creates a binding for a field that belongs to the class being created.

        Example

        
             Person person = Instancio.of(Person.class)
                     .ignore(field("fullName")) // Person.fullName
                     .create();
         
        Parameters:
        fieldName - field name to bind
        Returns:
        binding
      • all

        public static Binding all​(Class<?> type)
        Creates a binding for the given type.

        If the type is a primitive or wrapper, this method will only bind the specified type. For example:

        • all(int.class) - binds primitive int; does not include Integer
        • all(Integer.class) - binds Integer wrapper; does not include primitive int

        In order to bind both, primitive int and wrapper, use the allInts().

        Parameters:
        type - to bind
        Returns:
        binding
      • allStrings

        public static Binding allStrings()
        Shorthand for all(String.class).
        Returns:
        binding for all Strings
      • allBytes

        public static Binding allBytes()
        Binding for all bytes, primitive and wrapper.
        Returns:
        binding for all bytes
      • allFloats

        public static Binding allFloats()
        Binding for all floats, primitive and wrapper.
        Returns:
        binding for all floats
      • allShorts

        public static Binding allShorts()
        Binding for all shorts, primitive and wrapper.
        Returns:
        binding for all shorts
      • allInts

        public static Binding allInts()
        Binding for all integers, primitive and wrapper.
        Returns:
        binding for all integers
      • allLongs

        public static Binding allLongs()
        Binding for all longs, primitive and wrapper.
        Returns:
        binding for all longs
      • allDoubles

        public static Binding allDoubles()
        Binding for all doubles, primitive and wrapper.
        Returns:
        binding for all doubles
      • allBooleans

        public static Binding allBooleans()
        Binding for all booleans, primitive and wrapper.
        Returns:
        binding for all booleans
      • allChars

        public static Binding allChars()
        Binding for all characters, primitive and wrapper.
        Returns:
        binding for all characters