Grails 도메인 클래스에 문제가 있습니다. net.sf.json.JSONObject에서 도메인 클래스 객체를 작성하기 위해 생성자를 재정의했습니다. 이것은 컨트롤러를 통해 객체를 구별 할 때 잘 동작합니다. 그럼 테스트 케이스를 통해 인스턴스를 시도하고, 예외가 있어요 : (java.lang.String의) 값 : 인수의 형태에 적용 profileplugin.Contact.addToEmails() 메소드의Grails addTo * 생성되지 않음
없음 서명을 [뭔가를 @ something.com]
또한이 방법은 일부 클래스에서는 작동하지만 다른 클래스에서는 작동하지 않는 것으로 지적해야합니다. 매우 실망 스럽습니다. Grails에 익숙하지 않습니다. 누군가가 올바른 방향으로 나를 가리킬 수 있다면, 대단히 감사하겠습니다.
내 도메인 클래스 코드는 다음과 같습니다.
package profileplugin
import net.sf.json.JSONObject
class Contact
{
static hasMany =
[
phones: String,
faxes: String,
emails: String,
websites: String,
];
Contact() {}; // standard constructor must be specified, or grails dies
Contact(JSONObject source)
{
source.get('emails').each() { this.addToEmails(it); };
source.get('websites').each() { this.addToWebsites(it); };
source.get('phones').each() { this.addToPhones(it); };
source.get('faxes').each() { this.addToFaxes(it); };
};
}
그리고 여기가 마침내, 여기에 (아래 피드백을받은 후) 작업 코드의 버전입니다 ...
[
addresses:[],
phones:["(555) 555-7011"],
faxes:[],
emails:["[email protected]"],
websites:["http://www.google.com"]
]
예를 들어 소스 JSON 문자열이고 :
class Contact
{
def phones = [];
def faxes = [];
def emails = [];
def websites = [];
Contact() {}; // standard constructor must be specified, or grails dies
Contact(JSONObject source)
{
print source;
source.get('phones').each() { this.phones.add(it); };
source.get('emails').each() { this.emails.add(it); };
source.get('websites').each() { this.websites.add(it); };
source.get('faxes').each() { this.faxes.add(it); };
};
}
당신이 우리가 살펴 수있는 샘플 프로젝트를 압축 할 수 벤에
덕분? – Mengu