控制器
*.bat
TempOAuthToken.java
import com.google.gson.JsonObject;
import javax.ws.rs.core.Response;
@RestController
@RequestMapping(value = "/auth")
public class OAuthController {
@Autowired
private OAuthService oAuthService;
@RequestMapping(value = "/authorization-url", method = RequestMethod.GET)
public Response getAuthorizationUrl() {
try {
TempOAuthToken tempOAuthToken = oAuthService.getTemporaryOAuthToken();
return Response.status(Response.Status.OK).entity(tempOAuthToken.toJsonObject()).build();
} catch (Exception e) {
e.printStackTrace();
JsonObject errResponse = new JsonObject();
errResponse.addProperty("error", e.getMessage());
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errResponse).build();
}
}
}
我使用public class TempOAuthToken {
private String requestToken;
private String tokenSecret;
private String authorizationUrl;
private String verificationSecret;
public JsonObject toJsonObject() {
JsonObject json = new JsonObject();
json.addProperty("requestToken", this.requestToken);
json.addProperty("tokenSecret", this.tokenSecret);
json.addProperty("authorizationUrl", this.authorizationUrl);
return json;
}
}
作为返回类型。因此,我可以返回其中包含任何内容的JsonObject。我编写了javax.ws.rs.core.Response
方法将toJsonObject
模型转换为JsonObject。我遇到以下错误:
TempOAuthToken
似乎正在引用自身来创建周期。有人可以帮助我找到问题吗?