API for clojure.java.data - java.data 1.0.96-SNAPSHOT (in development)

by Cosmin Stejerean, Sean Corfield

Full namespace name: clojure.java.data

Overview

Support for recursively converting Java beans to Clojure and vice versa.

Public Variables and Functions



*to-java-object-missing-setter*

dynamic var

    
Specify the behavior of missing setters in to-java in the
default object case, using one of :ignore, :log, :error

    
    
    Source
  


from-java

multimethod
No usage documentation available
Convert a Java object to a Clojure map.

    
    
    Source
  


from-java-deep

multimethod
No usage documentation available
Convert a Java object to a Clojure map (converting deeply).

The second argument is a hash map that offers some control over the
conversion:
* :add-class -- if true, add :class with the actual class of the object
        being converted -- this mimics clojure.core/bean.
* :exceptions -- controls how getter exceptions should be handled:
        * :group -- return an :exceptions hash map in the object that
              contains all the properties that failed, with their exceptions,
        * :omit -- ignore exceptions and omit the properties that caused them,
        * :qualify -- return the exception as :<property>/exception and
              omit the property itself,
        * :return -- simply return the exception as the value of the property.
* :omit -- a set of properties (keywords) to omit from the conversion
        so that unsafe methods are not called (this applies across the whole
        recursive/deep conversion).

    
    
    Source
  


from-java-shallow

multimethod
No usage documentation available
Convert a Java object to a Clojure map (but do not convert deeply).

The second argument is a hash map that offers some control over the
conversion:
* :add-class -- if true, add :class with the actual class of the object
        being converted -- this mimics clojure.core/bean.
* :exceptions -- controls how getter exceptions should be handled:
        * :group -- return an :exceptions hash map in the object that
              contains all the properties that failed, with their exceptions,
        * :omit -- ignore exceptions and omit the properties that caused them,
        * :qualify -- return the exception as :<property>/exception and
              omit the property itself,
        * :return -- simply return the exception as the value of the property.
* :omit -- a set of properties (keywords) to omit from the conversion
        so that unsafe methods are not called.

    
    
    Source
  


set-properties

function
Usage: (set-properties instance props)
Given an existing Java object and a Clojure map, use reflection to
set the properties.

    
    
    Source
  


to-java

multimethod
No usage documentation available
Convert Clojure data to an instance of the specified Java class.
Several basic types have obvious conversions, but for a hash map
reflection is used to set the properties. If the class is an interface, we
can't create an instance of it, unless the Clojure map already implements it.

When java.time.Instant is available (Java 8+), we can convert a hash map
containing :nano and :epochSecond to Instant, as this is the reverse of
Instant->map.

A XMLGregorianCalendar object can be constructed from the following keys
:year, :month, :day, :hour, :minute, :second, and :timezone.

    
    
    Source
  

clojure.java.data.builder

A variant of clojure.java.data/to-java that uses a Builder class
to build the requested class from a hash map of properties.

Public Variables and Functions



to-java

function
Usage: (to-java clazz props)
       (to-java clazz props opts)
       (to-java clazz instance props opts)
       (to-java clazz builder instance props opts)
Given a class and a hash map of properties, figure out the Builder class,
figure out the setters for the Builder, construct an instance of it and
produce an instance of the original class. A hash map of options may also
be provided.

Alternatively, given a class, a builder instance, a hash map of properties,
and a hash map of options, figure out the setters for the builder class,
and use the builder instance to produce an instance of the original class.

Finally, given a class, a builder class, a builder instance (possibly of a
different class), a hash map of properties, and a hash map of options,
figure out the setters for the builder class, and use the builder instance
to produce an instance of the original class.

The following options may be provided:
* :builder-class -- the class that should be used for the builder process;
    by default we'll assume an inner class of clazz called 'Builder',
* :builder-props -- properties used to construct and initialize an instance
    of the builder class; defaults to an empty hash map; may have
    :clojure.java.data/constructor as metadata to provide constructor
    arguments for the builder instance,
* :build-fn -- the name of the method in the Builder class to use to
    complete the builder process and return the desired class;
    by default we'll try to deduce it, preferring 'build' if we find
    multiple candidates,
* :ignore-setters? -- a flag to indicate that methods on the builder
    class that begin with 'set' should be ignored, which may be
    necessary to avoid ambiguous methods that look like builder properties;
    by default 'setFooBar` will be treated as a builder property 'fooBar'
    if it accepts a single argument and returns a builder instance.

    
    
    Source
  
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.