I have a Java / Jersey service that returns a Boolean pro for AngularJs. In my controller, I get the value of the return from the promise, but it returns me an Object. In other cases, as a return from a User entity, for example, it works fine, because I get the attributes of the returned object. Now when it returns only a boolean, how do I recover the value?
Below is an example I'm using:
Java service:
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/verificaEmail")
public Boolean verificarEmail(String email){
SimpleEntityManager simpleEntityManager = new SimpleEntityManager(persistenceUnitName);
IUsuarioBusiness usuarioB = new UsuarioBusiness(simpleEntityManager);
Boolean result = usuarioB.verificaEmail(email);
return result;
}
Angular Controller:
this.cadastrarUsuario = function() {
var usuario = {
email: this.usuarioLogin.email,
senha: this.usuarioLogin.senha,
nome: this.usuarioLogin.nome
}
var verificaEmail = VerificaEmail.email(usuario.email);
verificaEmail.$promise.then(
function success(result)
{
if (result) {
$scope.erro = true;
$scope.mensagemErro = "Email já existe!";
$scope.mostraMensagem = true;
$scope.setClasseErro();
}
})};
Service:
var servicoLogin = angular.module('servicoLogin', ['ngResource']);
servicoLogin.factory('VerificaEmail', ['$resource',
function($resource){
return $resource('http://localhost:8081/GameService/webserver/usuario/verificaEmail', {}, {
email: {method:'POST'}
});
}]);
I'm just asking for help because I've already broken my head and I have not been able to solve this problem that seems to be simple.