How to read a return Map<String, String> Java in javascript?

Asked

Viewed 189 times

1

When making a request to a java control that returns a key map and value "String":

@ControllerSupport
public Map< String, String > teste() {
    Map< String, String > teste = new HashMap< String, String >();
    teste.put( "Teste", "Teste" );
    return teste;
}

When printing the request assigned to the variable accessing the service.

console.log($scope.teste);

Returned an error in the javascript log.

Error: [$resource:badcfg] Error in resource configuration. Expected response to contain an array but got an object

How to get this value returned from Map in Javascrip?

  • This variable receives the value of the service that then fetches the value in the java controller on the back.

1 answer

2


To determine with certainty the problem would have to have the code that makes the call, but based on two answers of the OS with the same error message, I can assume that the problem can be fixed using one of the solutions below.

  1. You can add isArray: false if you’re using the action query, thus:

    'query: {method: 'GET', isArray: false }

  2. Or you can try to use the action get instead of query.

  • I was really hoping that the request would be an array, with this modification to false now taking the right object. Thank you!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.