JIRA
JSON
개체를 마샬링하기 위해 data
레코드를 쓰고 있습니다. 문제는 이름/값 쌍에 대해 여러 객체의 레이블이 동일하다는 것입니다.하스켈 이름 공간에 대처하는 방법은 무엇입니까?
(컬에서 반환 형식) 내가 얻는 문제에 대응 하스켈 data
기록을 구성 할 때
{"expand":"schema,names"
,"startAt":0
,"maxResults":2
,"total":74
,"issues":[
{"expand":"editmeta,renderedFields,transitions,changelog,operations"
,"id":"183614"
,"self":"https://10.64.16.44/rest/api/latest/issue/183614"
,"key":"BNAP-339"
,"fields":{"versions":[
{"self":"https://10.64.16.44/rest/api/2/version/28240"
,"id":"28240"
,"name":"2012-12-07"
,"archived":false
,"released":false
}
]
,"status":{"self":"https://10.64.16.44/rest/api/2/status/1"
,"description":"The issue is open and ready for the assignee to start work on it."
,"iconUrl":"https://10.64.16.44/images/icons/status_open.gif"
,"name":"Open"
,"id":"1"
}
,"description":"Do Re Mi Fa"
,"resolution":null
}
}
]
하기 :
이data Issue = Issue {expand :: String
,id :: String
,self :: String
,key :: String
,fields :: Fields
} deriving Generic
data Version = Version {self :: String
,id :: String
,name :: String
,archived :: Bool
,released :: Bool
} deriving Generic
와 'ID'와 '자기'충돌합니다 예를 들어, . 나에게 레코드의 이름을 변경하고 수동으로 생성 된 FromJSON
인스턴스로 수정하여이를 해결할 수있었습니다. 다른 대안 솔루션을 환영합니다.
참고 : 예를 들어, 다음 데이터 형식 필드 충돌없이 값을 표시 할 수있다. 그러나 interop 목적을 위해 non-Haskell 코드의 구조를 맞추려고 할 때, 다른 쪽이 오버로드 된 함수 및/또는 하위 유형 계층에 크게 의존한다면 더 나은 접근법이 없을 수 있습니다. –
별도의 파일을 추천 한 부분을 upvoting했습니다. 유형 클래스는 사용자가 유형에 대해 추론하기가 매우 어렵고 잘못된 유형에 적용될 때 자동으로 실패하고 잘못된 작업을 수행하기 때문에 빈약 한 이름 공간 솔루션을 만듭니다. –