Annotation Interface StringCtor


Identifies the exact static factory method to use for creating an instance of a POJO from a string.

By default, ClassMeta.newInstanceFromString(Object,String) looks for a static method matching one of a fixed set of conventional names (fromString, fromValue, valueOf, parse, parseString, forName, forString) that takes a single String argument and returns an instance of the class, falling back to a single-String-arg constructor if none is found.

This annotation lets you opt out of that name-based guessing and explicitly name the static factory method to use, which is useful for classes whose factory method doesn't match any of the conventional names (e.g. of or create).

The annotated method must be static, return an instance of the class (or a subtype), and take exactly one String argument.

Example:

@StringCtor("of") public class MyClass { public static MyClass of(String value) { return new MyClass(value); } ... }

See Also:
Since:
9.2.0
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The name of the static factory method to use for string-convertibility.
  • Element Details

    • value

      The name of the static factory method to use for string-convertibility.

      The named method must be static, return an instance of the annotated class, and take exactly one String argument.

      Returns:
      The annotation value.