Package com.isomorphic.js

# Interface IToJSON

All Known Implementing Classes:
  `AIDataSource`, `BasicDataSource`, `DataSource`, `GAEJPADataSource`, `HibernateDataSource`, `JPA2DataSource`, `JPADataSource`, `ODataDataSource`, `ParquetDataSource`, `Project`, `RestConnector`, `RESTDataSource`, `Screen`, `SQLDataSource`

public interface IToJSON
Mark with and implement this interface on any class you want to make JS-serializeable by the ISC server engine.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `toJSON(Writer out, JSTranslater jsTrans)`
  Translate this object to executable JavaScript for transport to the browser.

- ## Method Details

  - ### toJSON

    void toJSON(Writer out, JSTranslater jsTrans) throws UnconvertableException, IOException
    Translate this object to executable JavaScript for transport to the browser.

    This example shows a simple way to customize Bean translation by implementing the IToJSON interface.

         class MyBean implements IToJSON {
            public void toJSON (Writer out, JSTranslater jsTrans) {
               try {
                  Map beanProps = DataTools.getProperties(this);
                  // here, remove any properties you don't want to send
                  // (or add or modify any others)
                  jsTrans.toJS(beanProps, out);
               } catch (Exception ignored) {}
            }
         }

    In this example we use DataTools.getProperties() to get all of the Bean's public properties as a Map. This Map can be modified arbitrarily, then the JSTranslater is invoked to transform the Map to a JavaScript Object. The same approach can be used externally to an object if you can't add the IToJSON interface.

    Note that this example reused the JSTranslater instance passed as a parameter - you should do this, rather than retrieving a new JSTranslater, because it preserves automatic recursion detection built into the JSTranslater class.

    As an alternative to implementing IToJSON, you can wrap objects in a `JSONFilter` before they are passed to the JSTranlater class.

    Parameters:
      `out` - Write your javascript translation of this object to this writer.
      `jsTrans` - The calling JSTranslater instance
    Throws:
      `UnconvertableException` - if the object cannot be converted to JSON
      `IOException` - if an I/O error occurs during writing
    See Also:
      - `JSTranslater`
      - `JSONFilter`
      - `DataTools.getProperties(Object)`