2011-11-26 8 views
0

JSON을 반환하는 REST 웹 서비스가 있습니다. {"oslc_cm:results":[{"dc:identifier":7,"calm:relatedTestCase":[],"calm:relatedTestScript":[],"rtc_cm:com.ibm.team.build.linktype.includedDeployments.com.ibm.team.build.common.link.includedInDeployment":[],"calm:relatedTestPlan":[],"rtc_cm:com.ibm.team.enterprise.deployment.linktype.deploymentDefinition.packageDefinition":[],"rtc_cm:com.ibm.team.workitem.linktype.attachment.attachment":[],"rtc_cm:state":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/workflows\/_X1GzsPC9EeCek69P-ztT9w\/states\/com.ibm.team.workitem.taskWorkflow\/1"},"rtc_cm:com.ibm.team.enterprise.packaging.linktype.resultWorkItem.result":[],"calm:tracksChanges":[],"rtc_cm:contextId":"_X1GzsPC9EeCek69P-ztT9w","rtc_cm:com.ibm.team.workitem.linktype.copiedworkitem.copies":[],"rtc_cm:com.ibm.team.workitem.linktype.resolvesworkitem.resolvedBy":[],"rtc_cm:com.ibm.team.enterprise.promotion.linktype.resultWorkItem.promoted":[],"rtc_cm:com.ibm.team.enterprise.package.linktype.packageDefinition.packageDefinition":[],"dc:creator":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/users\/_hhbosPC1EeCsJbI2ZgPDog"},"rtc_cm:com.ibm.team.workitem.linktype.copiedworkitem.copiedFrom":[],"rtc_cm:modifiedBy":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/users\/_hhbosPC1EeCsJbI2ZgPDog"},"rtc_cm:ownedBy":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/users\/_hhbosPC1EeCsJbI2ZgPDog"},"oslc_cm:severity":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/enumerations\/_X1GzsPC9EeCek69P-ztT9w\/severity\/severity.literal.l3"},"rtc_cm:com.ibm.team.enterprise.deployment.linktype.deploymentBuildResult.packageBuildResult":[],"calm:relatedExecutionRecord":[],"rdf:resource":"https:\/\/localhost:9443\/ccm\/resource\/itemName\/com.ibm.team.workitem.WorkItem\/7","calm:affectsExecutionResult":[],"rtc_cm:projectArea":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/projectareas\/_X1GzsPC9EeCek69P-ztT9w"},"rtc_cm:com.ibm.team.enterprise.packaging.linktype.resultWorkItem.promoted":[],"rtc_cm:com.ibm.team.workitem.linktype.schedulePredecessor.predecessor":[],"rtc_cm:correctedEstimate":null,"rtc_cm:teamArea":null,"rtc_cm:com.ibm.team.enterprise.promotion.linktype.promotionBuildResult.promotionBuildResult":[],"rtc_cm:com.ibm.team.enterprise.promotion.linktype.promotedChangeSets.promotedChangeSets":[],"dc:created":"2011-10-07T08:36:36.166Z","rtc_cm:resolution":null,"rtc_cm:archived":false,"rtc_cm:com.ibm.team.workitem.linktype.blocksworkitem.dependsOn":[],"calm:affectsPlanItem":[],"dc:subject":"","rtc_cm:resolvedBy":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/users\/_YNh4MOlsEdq4xpiOKg5hvA"},"calm:relatedTestSuite":[],"rtc_cm:com.ibm.team.workitem.linktype.parentworkitem.parent":[],"rtc_cm:filedAgainst":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/resource\/itemOid\/com.ibm.team.workitem.Category\/_ZQ3nEvC9EeCek69P-ztT9w"},"rtc_cm:com.ibm.team.workitem.linktype.relatedartifact.relatedArtifact":[],"dc:type":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/types\/_X1GzsPC9EeCek69P-ztT9w\/task"},"rtc_cm:com.ibm.team.enterprise.promotion.linktype.promotedBuildMaps.promotedBuildMaps":[],"dc:modified":"2011-10-07T08:51:52.006Z","rtc_cm:estimate":null,"rtc_cm:comments":[],"rtc_cm:plannedFor":null,"rtc_cm:com.ibm.team.workitem.linktype.textualReference.textuallyReferenced":[],"rtc_cm:com.ibm.team.connector.ccbridge.common.ver2wi.s":[],"rtc_cm:com.ibm.team.workitem.linktype.duplicateworkitem.duplicateOf":[],"rtc_cm:foundIn":null,"calm:tracksRequirement":[],"calm:implementsRequirement":[],"rtc_cm:com.ibm.team.workitem.linktype.resolvesworkitem.resolves":[],"rtc_cm:com.ibm.team.scm.svn.linkType.workItem.s":[],"rtc_cm:com.ibm.team.enterprise.promotion.linktype.resultWorkItem.result":[],"rtc_cm:com.ibm.team.workitem.linktype.relatedworkitem.related":[],"rtc_cm:timeSheet":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/workitems\/_ZadWAPC_EeC8XKWU4bgPxg\/rtc_cm:timeSheet"},"rtc_cm:com.ibm.team.workitem.linktype.blocksworkitem.blocks":[],"rtc_cm:com.ibm.team.build.linktype.reportedWorkItems.com.ibm.team.build.common.link.reportedAgainstBuilds":[],"rtc_cm:com.ibm.team.workitem.linktype.parentworkitem.children":[],"rtc_cm:com.ibm.team.enterprise.promotion.linktype.promotionDefinition.promotionDefinition":[],"rtc_cm:due":null,"rtc_cm:com.ibm.team.workitem.linktype.schedulePredecessor.successor":[],"rtc_cm:com.ibm.team.filesystem.workitems.change_set.com.ibm.team.scm.ChangeSet":[],"calm:relatedRequirement":[],"rtc_cm:timeSpent":null,"rtc_cm:resolved":null,"rtc_cm:startDate":null,"dc:title":"Test1","rtc_cm:progressTracking":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/workitems\/_ZadWAPC_EeC8XKWU4bgPxg\/progressTracking"},"rtc_cm:com.ibm.team.build.linktype.includedWorkItems.com.ibm.team.build.common.link.includedInBuilds":[],"calm:elaboratedByArchitectureElement":[],"oslc_cm:priority":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/enumerations\/_X1GzsPC9EeCek69P-ztT9w\/priority\/priority.literal.l01"},"rtc_cm:subscribers":[{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/users\/_hhbosPC1EeCsJbI2ZgPDog"}],"rtc_cm:com.ibm.team.workitem.linktype.duplicateworkitem.duplicates":[],"calm:testedByTestCase":[],"rtc_cm:com.ibm.team.build.linktype.includedPackages.com.ibm.team.build.common.link.includedInPackages":[],"dc:description":"","calm:blocksTestExecutionRecord":[],"rtc_cm:com.ibm.team.enterprise.package.linktype.packageBuildResult.packageBuildResult":[],"calm:affectedByDefect":[],"rtc_cm:com.ibm.team.connector.ccbridge.common.act2wi.s":[],"oslc_cm:relatedChangeManagement":[]},{"dc:identifier":14,"calm:relatedTestCase":[],"calm:relatedTestScript":[],"rtc_cm:com.ibm.team.build.linktype.includedDeployments.com.ibm.team.build.common.link.includedInDeployment":[],"calm:relatedTestPlan":[],"rtc_cm:com.ibm.team.enterprise.deployment.linktype.deploymentDefinition.packageDefinition":[],"rtc_cm:com.ibm.team.workitem.linktype.attachment.attachment":[],"rtc_cm:state":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/workflows\/_X1GzsPC9EeCek69P-ztT9w\/states\/com.ibm.team.workitem.defectWorkflow\/1"},"rtc_cm:com.ibm.team.enterprise.packaging.linktype.resultWorkItem.result":[],"calm:tracksChanges":[],"rtc_cm:contextId":"_X1GzsPC9EeCek69P-ztT9w","rtc_cm:com.ibm.team.workitem.linktype.copiedworkitem.copies":[],"rtc_cm:com.ibm.team.workitem.linktype.resolvesworkitem.resolvedBy":[],"rtc_cm:com.ibm.team.enterprise.promotion.linktype.resultWorkItem.promoted":[],"rtc_cm:com.ibm.team.enterprise.package.linktype.packageDefinition.packageDefinition":[],"dc:creator":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/users\/_hhbosPC1EeCsJbI2ZgPDog"},"rtc_cm:com.ibm.team.workitem.linktype.copiedworkitem.copiedFrom":[],"rtc_cm:modifiedBy":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/users\/_hhbosPC1EeCsJbI2ZgPDog"},"rtc_cm:ownedBy":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/users\/_hhbosPC1EeCsJbI2ZgPDog"},"oslc_cm:severity":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/enumerations\/_X1GzsPC9EeCek69P-ztT9w\/severity\/severity.literal.l3"},"rtc_cm:com.ibm.team.enterprise.deployment.linktype.deploymentBuildResult.packageBuildResult":[],"calm:relatedExecutionRecord":[],"rdf:resource":"https:\/\/localhost:9443\/ccm\/resource\/itemName\/com.ibm.team.workitem.WorkItem\/14","calm:affectsExecutionResult":[],"rtc_cm:projectArea":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/projectareas\/_X1GzsPC9EeCek69P-ztT9w"},"rtc_cm:com.ibm.team.enterprise.packaging.linktype.resultWorkItem.promoted":[],"rtc_cm:com.ibm.team.workitem.linktype.schedulePredecessor.predecessor":[],"rtc_cm:correctedEstimate":null,"rtc_cm:teamArea":null,"rtc_cm:com.ibm.team.enterprise.promotion.linktype.promotionBuildResult.promotionBuildResult":[],"rtc_cm:com.ibm.team.enterprise.promotion.linktype.promotedChangeSets.promotedChangeSets":[],"dc:created":"2011-10-14T12:02:30.283Z","rtc_cm:resolution":null,"rtc_cm:archived":false,"rtc_cm:com.ibm.team.workitem.linktype.blocksworkitem.dependsOn":[],"calm:affectsPlanItem":[],"dc:subject":"","rtc_cm:resolvedBy":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/users\/_YNh4MOlsEdq4xpiOKg5hvA"},"calm:relatedTestSuite":[],"rtc_cm:com.ibm.team.workitem.linktype.parentworkitem.parent":[],"rtc_cm:filedAgainst":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/resource\/itemOid\/com.ibm.team.workitem.Category\/_ZQ3nEvC9EeCek69P-ztT9w"},"rtc_cm:com.ibm.team.workitem.linktype.relatedartifact.relatedArtifact":[],"dc:type":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/types\/_X1GzsPC9EeCek69P-ztT9w\/defect"},"rtc_cm:com.ibm.team.enterprise.promotion.linktype.promotedBuildMaps.promotedBuildMaps":[],"dc:modified":"2011-10-14T12:03:43.215Z","rtc_cm:estimate":null,"rtc_cm:comments":[],"rtc_cm:plannedFor":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/iterations\/_YD4PgPC9EeCek69P-ztT9w"},"rtc_cm:com.ibm.team.workitem.linktype.textualReference.textuallyReferenced":[],"rtc_cm:com.ibm.team.connector.ccbridge.common.ver2wi.s":[],"rtc_cm:com.ibm.team.workitem.linktype.duplicateworkitem.duplicateOf":[],"rtc_cm:foundIn":null,"calm:tracksRequirement":[],"calm:implementsRequirement":[],"rtc_cm:com.ibm.team.workitem.linktype.resolvesworkitem.resolves":[],"rtc_cm:com.ibm.team.scm.svn.linkType.workItem.s":[],"rtc_cm:com.ibm.team.enterprise.promotion.linktype.resultWorkItem.result":[],"rtc_cm:com.ibm.team.workitem.linktype.relatedworkitem.related":[],"rtc_cm:timeSheet":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/workitems\/_Vo0mcPZcEeCfT6LO8_tPoQ\/rtc_cm:timeSheet"},"rtc_cm:com.ibm.team.workitem.linktype.blocksworkitem.blocks":[],"rtc_cm:com.ibm.team.build.linktype.reportedWorkItems.com.ibm.team.build.common.link.reportedAgainstBuilds":[],"rtc_cm:com.ibm.team.workitem.linktype.parentworkitem.children":[],"rtc_cm:com.ibm.team.enterprise.promotion.linktype.promotionDefinition.promotionDefinition":[],"rtc_cm:due":null,"rtc_cm:com.ibm.team.workitem.linktype.schedulePredecessor.successor":[],"rtc_cm:com.ibm.team.filesystem.workitems.change_set.com.ibm.team.scm.ChangeSet":[],"calm:relatedRequirement":[],"rtc_cm:timeSpent":null,"rtc_cm:resolved":null,"rtc_cm:startDate":null,"dc:title":"TestDefect1","rtc_cm:progressTracking":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/workitems\/_Vo0mcPZcEeCfT6LO8_tPoQ\/progressTracking"},"rtc_cm:com.ibm.team.build.linktype.includedWorkItems.com.ibm.team.build.common.link.includedInBuilds":[],"calm:elaboratedByArchitectureElement":[],"oslc_cm:priority":{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/enumerations\/_X1GzsPC9EeCek69P-ztT9w\/priority\/priority.literal.l07"},"rtc_cm:subscribers":[{"rdf:resource":"https:\/\/localhost:9443\/ccm\/oslc\/users\/_hhbosPC1EeCsJbI2ZgPDog"}],"rtc_cm:com.ibm.team.workitem.linktype.duplicateworkitem.duplicates":[],"calm:testedByTestCase":[],"rtc_cm:com.ibm.team.build.linktype.includedPackages.com.ibm.team.build.common.link.includedInPackages":[],"dc:description":"","calm:blocksTestExecutionRecord":[],"rtc_cm:com.ibm.team.enterprise.package.linktype.packageBuildResult.packageBuildResult":[],"calm:affectedByDefect":[],"rtc_cm:com.ibm.team.connector.ccbridge.common.act2wi.s":[],"oslc_cm:relatedChangeManagement":[]},],"oslc_cm:totalCount":2}Google의 GSON을 사용하여 JSON 유효하지 않은 식별자를 구문 분석하려면 어떻게해야합니까?

가 지금은 POJO 객체로이 변환 GSON를 사용하려면 : 예를 들어 나는 다음과 같은 응답이있다. 내가 ArrayList에이 이름 oslc_cm해야한다고 생각하기 때문에

public class JSONContainer { 

    ArrayList<JSONWorkItem> items = new ArrayList<JSONWorkItem>(); 

    public ArrayList<JSONWorkItem> getItems() { 
     return items; 
    } 

} 

이것은 작동하지 않습니다 : 최상위 루트 노드에 대해 나는 다음과 같은 클래스 생성 결과를, 그러나 이것은 유효한 Java 식별자하지 않기 때문에 나는 할수 없어. 그래서 내가 무엇을 할 수 있니?

답변

1

대답은 Gson User Guide에서 사용할 수 있습니다. 그 용도로 SerialName이라는 주석을 사용할 수 있습니다.

그래서 POJO 클래스는 다음과 같아야합니다

public class JSONContainer { 

    @SerializedName("oslc_cm:results") 
    ArrayList<JSONWorkItem> items = new ArrayList<JSONWorkItem>(); 

    public ArrayList<JSONWorkItem> getItems() { 
     return items; 
    } 

} 
관련 문제