////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you 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

https://www.apache.org/licenses/LICENSE-2.0

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.
////

It is possible to register custom converters to change how a given class is rendered with json views. To do so, create a class that implements link:{api}grails/plugin/json/builder/JsonGenerator.Converter.html[Converter]. Then you must register the class in `src/main/resources/META-INF/services/grails.plugin.json.builder.JsonGenerator$Converter`.

[source,groovy]
----
package foo

class MyConverter implements JsonGenerator.Converter {

    @Override
    boolean handles(Class<?> type) {
        CustomClass.isAssignableFrom(type)
    }

    @Override
    Object convert(Object value, String key) {
        ((CustomClass)value).name
    }
}


class CustomClass {
    String name
}
----

Because plugins could potentially provide converters, you can also determine the order by implementing the http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/core/Ordered.html[Ordered] interface in your converter.

[source]
.src/main/resources/META-INF/services/grails.plugin.json.builder.JsonGenerator$Converter
----
foo.MyCustomConverter
----

NOTE: If you have multiple classes to register, put each one on it's own line
