나는 대부분이 문제를 해결했지만 끝에는 오류 추적을 알 수 없다. 아마 미묘한 일이 될 것이다.이 필드 값을 맵으로 정렬
GSON에 대한 해결 방법을 구현 중입니다. 실제 GSON은 problems parsing nested maps입니다.
public class RegisterValues
{
int Earth;
int Mars;
//etc for 200 planets
public Map returnValues()throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException{
final String [] fieldValues = new String[] {"Earth", "Mars", //etc }
RegisterValues regValues = new RegisterValues();
Map values = new HashMap<String, Integer>();
//values.put("Earth", Earth); manually this works, I'd rather loop through a readymade array of String values.
for (String value : fieldValues){
values.put(field, regValues.getClass().getField(field).getInt(field);) //here it breaks
}
return values;
}
}
오류 추적 :
Rebinding example.client.Panel // This is the class that is calling the above function
02:24:31.704 [DEBUG] Checking rule <generate-with class='com.google.gwtjsonrpc.rebind.RemoteJsonServiceProxyGenerator'/>
02:24:31.704 [ERROR] Errors in '.../RegisterValues.java'
02:24:31.704 [ERROR] Line 324: No source code is available for type java.lang.SecurityException; did you forget to inherit a required module?
02:24:31.704 [ERROR] Line 333: The method getField(String) is undefined for the type Class<capture#1-of ? extends RegisterValues>
모든 행 번호가 I이 클래스를 호출하는 부분을 참조한다. 수동으로 맵을 채울 때 작동하지만이 루핑 메소드를 수행하면 작동하지 않습니다.
기본적으로 위의 내용이 올바른지 궁금합니다.
(!) 참고 : 위에서 올 바르면,이 때문에이 그 즉 반사 클래스가 즉시 컴파일되어 있기 때문에 이것이 불가능되고 그것을이다 (GWT.create()) 나는이 부분에 액세스하는 경우에만 프로그램 - 따라서 그것은 어떤 문제가 있습니까?
컴파일 가능한 코드를 게시하면 도움이됩니다. –
호환되는 코드 란 무엇입니까? – fiz
기본적으로 문자열을 필드 이름으로 변경하는 것은 내가 원하는 것입니다. – fiz