2015-12-30 36 views
2

我在我的代碼中使用jsonschema2pojo時遇到問題。 所以,我用jsonschema2pojo發生器(http://www.jsonschema2pojo.org/),從這個URL生成POJO的:http://store.steampowered.com/api/appdetails/?appids=10帶URL的jsonschema2pojo不起作用

最後,我在一個包中「模式」創建所有這些類。 然後在我嘗試用它來讀取鏈接JSON,但我得到異常:

Exception in thread "main" java.lang.NullPointerException 
    at controller.View.main(View.java:26) 

我不明白爲什麼。 這裏是代碼我怎樣才能做到這一點:

public class View { 
private static String urlStr = "http://store.steampowered.com/api/appdetails/?appids=10"; 

public static void main(String[] args) { 

    ObjectMapper objectMapper = new ObjectMapper(); 

    try { 
     Game game = objectMapper.readValue(new URL(urlStr), Game.class); 

     System.out.println(game.getData().getName()); 
    } catch (MalformedURLException e) { 
     e.printStackTrace(); 
    } catch (JsonParseException e) { 
     e.printStackTrace(); 
    } catch (JsonMappingException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 


} 

}

的Game.class是finall類,我在發電機爲「類名」設置。

有什麼不對?我怎樣才能從這個鏈接獲取所有這些數據?

在行家我配置它這樣的:

<plugin> 
      <groupId>org.jsonschema2pojo</groupId> 
      <artifactId>jsonschema2pojo-maven-plugin</artifactId> 
      <version>0.4.18</version> 
      <configuration> 
       <sourceType>jsonschema</sourceType> 
       <outputEncoding>${project.build.sourceEncoding}</outputEncoding> 
       <outputDirectory>${project.build.directory}/generated-sources</outputDirectory> 
       <annotationStyle>jackson2</annotationStyle> 
       <generateBuilders>true</generateBuilders> 
       <initializeCollections>true</initializeCollections> 
      </configuration> 
      <executions> 
       <execution> 
        <id>generate-game</id> 
        <goals> 
         <goal>generate</goal> 
        </goals> 
        <configuration> 
         <targetPackage>model.game</targetPackage> 
         <sourceDirectory>${basedir}/src/main/resources/schema/game</sourceDirectory> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

正如我所說的,所有的類都是在的src/main/java和包裝 '模式',我的模式是在SR /主/資源/模式/在文件「遊戲」

我的模式是這樣的:

{ 
    "type": "object", 
    "required":false, 
    "javaType":"model.Game", 
    "properties": { 
    "10": { 
     "id": "10", 
     "type": "object", 
     "properties": { 
     "success": { 
      "id": "success", 
      "type": "boolean" 
     }, 
     "data": { 
      "id": "data", 
      "type": "object", 
      "properties": { 
      "type": { 
       "id": "type", 
       "type": "string" 
      }, 
      "name": { 
       "id": "name", 
       "type": "string" 
      }, 
      "steam_appid": { 
       "id": "steam_appid", 
       "type": "integer" 
      }, 
      "required_age": { 
       "id": "required_age", 
       "type": "integer" 
      }, 
      "is_free": { 
       "id": "is_free", 
       "type": "boolean" 
      }, 
      "detailed_description": { 
       "id": "detailed_description", 
       "type": "string" 
      }, 
      "about_the_game": { 
       "id": "about_the_game", 
       "type": "string" 
      }, 
      "supported_languages": { 
       "id": "supported_languages", 
       "type": "string" 
      }, 
      "header_image": { 
       "id": "header_image", 
       "type": "string" 
      }, 
      "website": { 
       "id": "website", 
       "type": "null" 
      }, 
      "pc_requirements": { 
       "id": "pc_requirements", 
       "type": "object", 
       "properties": { 
       "minimum": { 
        "id": "minimum", 
        "type": "string" 
       } 
       } 
      }, 
      "mac_requirements": { 
       "id": "mac_requirements", 
       "type": "object", 
       "properties": { 
       "minimum": { 
        "id": "minimum", 
        "type": "string" 
       } 
       } 
      }, 
      "linux_requirements": { 
       "id": "linux_requirements", 
       "type": "object", 
       "properties": { 
       "minimum": { 
        "id": "minimum", 
        "type": "string" 
       } 
       } 
      }, 
      "developers": { 
       "id": "developers", 
       "type": "array", 
       "items": { 
       "id": "0", 
       "type": "string" 
       } 
      }, 
      "publishers": { 
       "id": "publishers", 
       "type": "array", 
       "items": { 
       "id": "0", 
       "type": "string" 
       } 
      }, 
      "price_overview": { 
       "id": "price_overview", 
       "type": "object", 
       "properties": { 
       "currency": { 
        "id": "currency", 
        "type": "string" 
       }, 
       "initial": { 
        "id": "initial", 
        "type": "integer" 
       }, 
       "final": { 
        "id": "final", 
        "type": "integer" 
       }, 
       "discount_percent": { 
        "id": "discount_percent", 
        "type": "integer" 
       } 
       } 
      }, 
      "packages": { 
       "id": "packages", 
       "type": "array", 
       "items": [ 
       { 
        "id": "0", 
        "type": "string" 
       }, 
       { 
        "id": "1", 
        "type": "integer" 
       }, 
       { 
        "id": "2", 
        "type": "integer" 
       }, 
       { 
        "id": "3", 
        "type": "integer" 
       } 
       ] 
      }, 
      "package_groups": { 
       "id": "package_groups", 
       "type": "array", 
       "items": { 
       "id": "0", 
       "type": "object", 
       "properties": { 
        "name": { 
        "id": "name", 
        "type": "string" 
        }, 
        "title": { 
        "id": "title", 
        "type": "string" 
        }, 
        "description": { 
        "id": "description", 
        "type": "string" 
        }, 
        "selection_text": { 
        "id": "selection_text", 
        "type": "string" 
        }, 
        "save_text": { 
        "id": "save_text", 
        "type": "string" 
        }, 
        "display_type": { 
        "id": "display_type", 
        "type": "integer" 
        }, 
        "is_recurring_subscription": { 
        "id": "is_recurring_subscription", 
        "type": "string" 
        }, 
        "subs": { 
        "id": "subs", 
        "type": "array", 
        "items": [ 
         { 
         "id": "0", 
         "type": "object", 
         "properties": { 
          "packageid": { 
          "id": "packageid", 
          "type": "string" 
          }, 
          "percent_savings_text": { 
          "id": "percent_savings_text", 
          "type": "string" 
          }, 
          "percent_savings": { 
          "id": "percent_savings", 
          "type": "integer" 
          }, 
          "option_text": { 
          "id": "option_text", 
          "type": "string" 
          }, 
          "option_description": { 
          "id": "option_description", 
          "type": "string" 
          }, 
          "can_get_free_license": { 
          "id": "can_get_free_license", 
          "type": "string" 
          }, 
          "is_free_license": { 
          "id": "is_free_license", 
          "type": "boolean" 
          }, 
          "price_in_cents_with_discount": { 
          "id": "price_in_cents_with_discount", 
          "type": "integer" 
          } 
         } 
         }, 
         { 
         "id": "1", 
         "type": "object", 
         "properties": { 
          "packageid": { 
          "id": "packageid", 
          "type": "integer" 
          }, 
          "percent_savings_text": { 
          "id": "percent_savings_text", 
          "type": "string" 
          }, 
          "percent_savings": { 
          "id": "percent_savings", 
          "type": "integer" 
          }, 
          "option_text": { 
          "id": "option_text", 
          "type": "string" 
          }, 
          "option_description": { 
          "id": "option_description", 
          "type": "string" 
          }, 
          "can_get_free_license": { 
          "id": "can_get_free_license", 
          "type": "string" 
          }, 
          "is_free_license": { 
          "id": "is_free_license", 
          "type": "boolean" 
          }, 
          "price_in_cents_with_discount": { 
          "id": "price_in_cents_with_discount", 
          "type": "integer" 
          } 
         } 
         }, 
         { 
         "id": "2", 
         "type": "object", 
         "properties": { 
          "packageid": { 
          "id": "packageid", 
          "type": "integer" 
          }, 
          "percent_savings_text": { 
          "id": "percent_savings_text", 
          "type": "string" 
          }, 
          "percent_savings": { 
          "id": "percent_savings", 
          "type": "integer" 
          }, 
          "option_text": { 
          "id": "option_text", 
          "type": "string" 
          }, 
          "option_description": { 
          "id": "option_description", 
          "type": "string" 
          }, 
          "can_get_free_license": { 
          "id": "can_get_free_license", 
          "type": "string" 
          }, 
          "is_free_license": { 
          "id": "is_free_license", 
          "type": "boolean" 
          }, 
          "price_in_cents_with_discount": { 
          "id": "price_in_cents_with_discount", 
          "type": "integer" 
          } 
         } 
         }, 
         { 
         "id": "3", 
         "type": "object", 
         "properties": { 
          "packageid": { 
          "id": "packageid", 
          "type": "integer" 
          }, 
          "percent_savings_text": { 
          "id": "percent_savings_text", 
          "type": "string" 
          }, 
          "percent_savings": { 
          "id": "percent_savings", 
          "type": "integer" 
          }, 
          "option_text": { 
          "id": "option_text", 
          "type": "string" 
          }, 
          "option_description": { 
          "id": "option_description", 
          "type": "string" 
          }, 
          "can_get_free_license": { 
          "id": "can_get_free_license", 
          "type": "string" 
          }, 
          "is_free_license": { 
          "id": "is_free_license", 
          "type": "boolean" 
          }, 
          "price_in_cents_with_discount": { 
          "id": "price_in_cents_with_discount", 
          "type": "integer" 
          } 
         } 
         } 
        ] 
        } 
       } 
       } 
      }, 
      "platforms": { 
       "id": "platforms", 
       "type": "object", 
       "properties": { 
       "windows": { 
        "id": "windows", 
        "type": "boolean" 
       }, 
       "mac": { 
        "id": "mac", 
        "type": "boolean" 
       }, 
       "linux": { 
        "id": "linux", 
        "type": "boolean" 
       } 
       } 
      }, 
      "metacritic": { 
       "id": "metacritic", 
       "type": "object", 
       "properties": { 
       "score": { 
        "id": "score", 
        "type": "integer" 
       }, 
       "url": { 
        "id": "url", 
        "type": "string" 
       } 
       } 
      }, 
      "categories": { 
       "id": "categories", 
       "type": "array", 
       "items": [ 
       { 
        "id": "0", 
        "type": "object", 
        "properties": { 
        "id": { 
         "id": "id", 
         "type": "integer" 
        }, 
        "description": { 
         "id": "description", 
         "type": "string" 
        } 
        } 
       }, 
       { 
        "id": "1", 
        "type": "object", 
        "properties": { 
        "id": { 
         "id": "id", 
         "type": "integer" 
        }, 
        "description": { 
         "id": "description", 
         "type": "string" 
        } 
        } 
       } 
       ] 
      }, 
      "genres": { 
       "id": "genres", 
       "type": "array", 
       "items": { 
       "id": "0", 
       "type": "object", 
       "properties": { 
        "id": { 
        "id": "id", 
        "type": "string" 
        }, 
        "description": { 
        "id": "description", 
        "type": "string" 
        } 
       } 
       } 
      }, 
      "screenshots": { 
       "id": "screenshots", 
       "type": "array", 
       "items": [ 
       { 
        "id": "0", 
        "type": "object", 
        "properties": { 
        "id": { 
         "id": "id", 
         "type": "integer" 
        }, 
        "path_thumbnail": { 
         "id": "path_thumbnail", 
         "type": "string" 
        }, 
        "path_full": { 
         "id": "path_full", 
         "type": "string" 
        } 
        } 
       }, 
       { 
        "id": "1", 
        "type": "object", 
        "properties": { 
        "id": { 
         "id": "id", 
         "type": "integer" 
        }, 
        "path_thumbnail": { 
         "id": "path_thumbnail", 
         "type": "string" 
        }, 
        "path_full": { 
         "id": "path_full", 
         "type": "string" 
        } 
        } 
       }, 
       { 
        "id": "2", 
        "type": "object", 
        "properties": { 
        "id": { 
         "id": "id", 
         "type": "integer" 
        }, 
        "path_thumbnail": { 
         "id": "path_thumbnail", 
         "type": "string" 
        }, 
        "path_full": { 
         "id": "path_full", 
         "type": "string" 
        } 
        } 
       }, 
       { 
        "id": "3", 
        "type": "object", 
        "properties": { 
        "id": { 
         "id": "id", 
         "type": "integer" 
        }, 
        "path_thumbnail": { 
         "id": "path_thumbnail", 
         "type": "string" 
        }, 
        "path_full": { 
         "id": "path_full", 
         "type": "string" 
        } 
        } 
       }, 
       { 
        "id": "4", 
        "type": "object", 
        "properties": { 
        "id": { 
         "id": "id", 
         "type": "integer" 
        }, 
        "path_thumbnail": { 
         "id": "path_thumbnail", 
         "type": "string" 
        }, 
        "path_full": { 
         "id": "path_full", 
         "type": "string" 
        } 
        } 
       }, 
       { 
        "id": "5", 
        "type": "object", 
        "properties": { 
        "id": { 
         "id": "id", 
         "type": "integer" 
        }, 
        "path_thumbnail": { 
         "id": "path_thumbnail", 
         "type": "string" 
        }, 
        "path_full": { 
         "id": "path_full", 
         "type": "string" 
        } 
        } 
       }, 
       { 
        "id": "6", 
        "type": "object", 
        "properties": { 
        "id": { 
         "id": "id", 
         "type": "integer" 
        }, 
        "path_thumbnail": { 
         "id": "path_thumbnail", 
         "type": "string" 
        }, 
        "path_full": { 
         "id": "path_full", 
         "type": "string" 
        } 
        } 
       }, 
       { 
        "id": "7", 
        "type": "object", 
        "properties": { 
        "id": { 
         "id": "id", 
         "type": "integer" 
        }, 
        "path_thumbnail": { 
         "id": "path_thumbnail", 
         "type": "string" 
        }, 
        "path_full": { 
         "id": "path_full", 
         "type": "string" 
        } 
        } 
       }, 
       { 
        "id": "8", 
        "type": "object", 
        "properties": { 
        "id": { 
         "id": "id", 
         "type": "integer" 
        }, 
        "path_thumbnail": { 
         "id": "path_thumbnail", 
         "type": "string" 
        }, 
        "path_full": { 
         "id": "path_full", 
         "type": "string" 
        } 
        } 
       }, 
       { 
        "id": "9", 
        "type": "object", 
        "properties": { 
        "id": { 
         "id": "id", 
         "type": "integer" 
        }, 
        "path_thumbnail": { 
         "id": "path_thumbnail", 
         "type": "string" 
        }, 
        "path_full": { 
         "id": "path_full", 
         "type": "string" 
        } 
        } 
       }, 
       { 
        "id": "10", 
        "type": "object", 
        "properties": { 
        "id": { 
         "id": "id", 
         "type": "integer" 
        }, 
        "path_thumbnail": { 
         "id": "path_thumbnail", 
         "type": "string" 
        }, 
        "path_full": { 
         "id": "path_full", 
         "type": "string" 
        } 
        } 
       }, 
       { 
        "id": "11", 
        "type": "object", 
        "properties": { 
        "id": { 
         "id": "id", 
         "type": "integer" 
        }, 
        "path_thumbnail": { 
         "id": "path_thumbnail", 
         "type": "string" 
        }, 
        "path_full": { 
         "id": "path_full", 
         "type": "string" 
        } 
        } 
       }, 
       { 
        "id": "12", 
        "type": "object", 
        "properties": { 
        "id": { 
         "id": "id", 
         "type": "integer" 
        }, 
        "path_thumbnail": { 
         "id": "path_thumbnail", 
         "type": "string" 
        }, 
        "path_full": { 
         "id": "path_full", 
         "type": "string" 
        } 
        } 
       } 
       ] 
      }, 
      "recommendations": { 
       "id": "recommendations", 
       "type": "object", 
       "properties": { 
       "total": { 
        "id": "total", 
        "type": "integer" 
       } 
       } 
      }, 
      "achievements": { 
       "id": "achievements", 
       "type": "object", 
       "properties": { 
       "total": { 
        "id": "total", 
        "type": "integer" 
       } 
       } 
      }, 
      "release_date": { 
       "id": "release_date", 
       "type": "object", 
       "properties": { 
       "coming_soon": { 
        "id": "coming_soon", 
        "type": "boolean" 
       }, 
       "date": { 
        "id": "date", 
        "type": "string" 
       } 
       } 
      }, 
      "support_info": { 
       "id": "support_info", 
       "type": "object", 
       "properties": { 
       "url": { 
        "id": "url", 
        "type": "string" 
       }, 
       "email": { 
        "id": "email", 
        "type": "string" 
       } 
       } 
      }, 
      "background": { 
       "id": "background", 
       "type": "string" 
      } 
      } 
     } 
     }, 
     "required": [ 
     "success", 
     "data", 
     "id", 
     "path_thumbnail", 
     "path_full" 
     ] 
    } 
    }, 
    "required": [ 
    "10" 
    ] 
} 

有了這個配置,我可以用這條線,而不是之前的System.out.println讀取所有數據:

System.out.println(objectMapper.writeValueAsString(game)); 

現在我可以看到完整的json字符串,但是如何使用'game.getData()。getName()'等來讀取它?

回答

0

您提供的JSON模式將「10」定義爲包含其他所有內容的頂級屬性。

{ 
    "type": "object", 
    "required":false, 
    "javaType":"model.Game", 
    "properties": { 
    "10": { 
     "id": "10", 
     "type": "object", 
     "properties": { 
     "success": { 
      "id": "success", 
      "type": "boolean" 
     }, 
     "data": { 
      "id": "data", 
      "type": "object", 
      "properties": { 
      "type": { 
       "id": "type", 
       "type": "string" 
      }, 
      "name": { 
       "id": "name", 
       "type": "string" 
      }, 
... 

jsonschema2pojo讀取模式,並生成一個名爲_10作爲模型的部件分類。您可以在_10.java中的generated-sources目錄中找到它。

@JsonInclude(JsonInclude.Include.NON_NULL) 
@Generated("org.jsonschema2pojo") 
@JsonPropertyOrder({ 
    "success", 
    "data" 
}) 
public class _10 { 

我不知道這是模式中的故意。如果它是故意的,那麼你需要像這樣訪問這個名字。

System.out.println(game.get10().getData().getName()); 

在做出更改後,我能夠正常工作。

編輯:它看起來這些JSON消息應該有一個變量ID作爲包含其他所有內容的頂級密鑰,所以我們需要處理這個有點不同。我們可以概括模式,以便它不是特定於特定ID,然後我們可以使用兩個步驟來解析消息。首先,我們將使用[ObjectMapper#readValue](https://fasterxml.github.io/jackson-databind/javadoc/2.5/com/fasterxml/jackson/databind/ObjectMapper.html#readValue(java.net.URL,com.fasterxml.jackson.core.type.TypeReference))將整個消息解析爲Map<String, Object>。我們預計頂層地圖將包含一個元素,與我們請求的文檔的ID相對應,其值將是包含我們感興趣的值的子地圖。然後,我們將傳遞該子地圖通過[ObjectMapper#convertValue](https://fasterxml.github.io/jackson-databind/javadoc/2.5/com/fasterxml/jackson/databind/ObjectMapper.html#convertValue(java.lang.Object,java.lang.Class))來獲得我們想要的Game對象。

的pom.xml

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>cnauroth</groupId> 
    <artifactId>test-json</artifactId> 
    <packaging>jar</packaging> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>Test JSON</name> 
    <description>Test JSON</description> 
    <build> 
     <plugins>    
      <plugin> 
       <groupId>org.jsonschema2pojo</groupId> 
       <artifactId>jsonschema2pojo-maven-plugin</artifactId> 
       <version>0.4.18</version> 
       <configuration> 
        <sourceType>jsonschema</sourceType> 
        <outputEncoding>${project.build.sourceEncoding}</outputEncoding> 
        <outputDirectory>${project.build.directory}/generated-sources/java</outputDirectory> 
        <annotationStyle>jackson2</annotationStyle> 
        <generateBuilders>true</generateBuilders> 
        <initializeCollections>true</initializeCollections> 
       </configuration> 
       <executions> 
        <execution> 
         <id>generate-game</id> 
         <goals> 
          <goal>generate</goal> 
         </goals> 
         <configuration> 
          <targetPackage>model.game</targetPackage> 
          <sourceDirectory>${basedir}/src/main/resources/schema/game</sourceDirectory> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <artifactId>maven-assembly-plugin</artifactId> 
       <configuration> 
        <archive> 
         <manifest> 
          <addDefaultImplementationEntries>true</addDefaultImplementationEntries> 
          <mainClass>View</mainClass> 
         </manifest> 
        </archive> 
        <descriptorRefs> 
         <descriptorRef>jar-with-dependencies</descriptorRef> 
        </descriptorRefs> 
        <finalName>${project.artifactId}</finalName> 
        <appendAssemblyId>false</appendAssemblyId> 
       </configuration> 
       <executions> 
        <execution> 
         <id>make-assembly</id> 
         <phase>package</phase> 
         <goals> 
          <goal>single</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
    <dependencies> 
     <dependency> 
      <groupId>com.fasterxml.jackson.core</groupId> 
      <artifactId>jackson-databind</artifactId> 
      <version>2.5.0</version> 
     </dependency> 
     <dependency> 
      <groupId>commons-lang</groupId> 
      <artifactId>commons-lang</artifactId> 
      <version>2.6</version> 
     </dependency> 
    </dependencies> 
</project> 

遊戲

的JSON模式文件太大無法粘貼,所以這裏是一個gist的鏈接。

View.java

import java.net.URI; 
import java.util.Map; 

import com.fasterxml.jackson.core.type.TypeReference; 
import com.fasterxml.jackson.databind.ObjectMapper; 

import model.Game; 

public class View { 

    public static void main(String[] args) throws Exception { 
     String id = args[0]; 
     URI uri = new URI("http", "store.steampowered.com", "/api/appdetails", 
       "appids=" + id, null); 
     ObjectMapper objectMapper = new ObjectMapper(); 
     Map<String, Object> obj = objectMapper.readValue(uri.toURL(), 
       new TypeReference<Map<String, Object>>(){}); 
     Game game = objectMapper.convertValue(obj.get(id), Game.class); 
     System.out.println(game.getData().getName()); 
    } 
} 

演示

> mvn clean package 

> java -jar target/test-json.jar 10 
Counter-Strike 

> java -jar target/test-json.jar 219 
Half-Life 2: Demo 

此外,我需要做出一個其他更改到架構。我刪除了linux_requirements屬性。這是因爲看文檔10與文檔219,它是前者中的一個對象,後者是一個數組。對於文檔219,解析器不知道如何理解數組,因爲我們期待着一個對象。從API返回的數據如此不一致,這很奇怪。您可能需要對模式進行一些修改,以使其完全適用於從該API返回的所有可能的JSON文檔。

我已將所有代碼放入GitHub repository。您可以獲取該代碼,構建它並運行它來查看它的工作情況。然後,你可以進一步適應你的需求。

+0

但是您是否嘗試在URL中使用其他ID如果此clas _10也適用於id = 219? – ullQuiorra

+0

我試圖做到像你一樣,但我得到了異常:無法識別的字段「steam_appid」(Class model.Data),未標記爲可忽略 – ullQuiorra

+0

如果ID(這是變量)預期作爲格式中的鍵,那麼你可能考慮做一個兩步的過程,將整個東西解析成一個沒有特定數據綁定的原始地圖,然後拉出與該鍵相對應的子地圖,然後通過序列化返回到JSON並反序列化來使該子地圖往返通用模式,它沒有指定「10」或任何其他特定的ID。 –

0

而不是嘗試使用properties對包含ID的對象建模,請使用additionalProperties。假設頂層類型包含了幾場比賽,你可以嘗試的東西代替

{ 
    "type": "object", 
    "required":false, 
    "javaType":"model.Game", 
    "properties": { 
    "10": { 
     "id": "10", 
     "type": "object", 
     ... 
    } 
    } 
} 

{ 
    "type": "object", 
    "required":false, 
    "javaType":"model.Games", 
    "additionalProperties": { 
     "id": "game", 
     "type": "object", 
     "javaType": "model.Game" 
     ... 
    } 
} 

這應該做出model.Games類型與像public Map<String, Game> getAdditionalProperties()的方法。