私は次のようなクラスを持っています:
class Foo {
    name
    description
    static constraints = {
        name()
        description()
    }
}
クラスの表示インスタンスをFlexigridに追加したい。データがflexigridに送信されるときは、JSONやXMLなどの形式である必要があります...私はJSONを選択しました。Flexigridは、受信するJSON配列が次の形式であることを想定しています。
{
    "page": "1",
    "total": "1",
    "rows": [
        {
            "id": "1",
            "cell": [
                "1",
                "The name of Foo 1",
                "The description of Foo 1"
            ]
        },
        {
            "id": "2",
            "cell": [
                "2",
                "The name of Foo 2",
                "The description of Foo 2"
            ]
        }
    ]
}
Fooオブジェクトをこの形式にするために、次のようなことを行います。
def foos = Foo.getAll( 1, 2 )
def results = [:]
results[ "page" ] = params.page
results[ "total" ] = foos.size()
results[ "rows" ] = []
for( foo in foos ) {
    def cell = []
    cell.add( foo.id )
    foo.getProperties().each() { key, value -> // Sometimes get foo.getProperties().each() returns foo.description then foo.name instead of foo.name then foo.description as desired.
        cell.add( value.toString() )
    }
    results[ "rows" ].add( [ "id": foo.id, "cell": cell ] )
}
render results as JSON
問題は、たまにfoo.getProperties().each()戻っfoo.descriptionて、 foo.nameflexigridfoo.descriptionの名前列にfoo.name入れられ、特定の行のflexigridの説明列に入れられることです。
Fooドメインクラスで制約を指定してgetProperties、が正しい順序で返されるようにしましたが、機能しませんでした。  予測可能な順序でプロパティを返すようにするにはどうすればよいですか?getProperties
これは私がこの問題を修正した方法です:
def items = Foo.getAll()
for( item in items ) {
    def cell = []
    cell.add( item.id )
    Foo.constraints.each() { key, value ->
        def itemValue = item.getProperty( key )
        if( !( itemValue instanceof Collection ) ) {
            cell.add( itemValue.toString() )
        }
    }
}
したがってFoo.constraints、各制約がのインスタンスである制約のマップを取得しますCollections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntry。テストの結果、このマップは常に静的制約を入力した順序で返すことがわかりましFooた(Ianによっても確認されています)。これで、のプロパティのみがitemforflexigridにFoo.constraints追加されます。cell