Restlet converts JSON to LinkedHashMap instead of List<MyObject>?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Restlet converts JSON to LinkedHashMap instead of List<MyObject>?

hhimanshu
This post has NOT been accepted by the mailing list yet.
This post was updated on .
This is what my `Rest` endpoint looks like  

     @Post("json")
      public List<LogProcessorExpression> addLogProcessorExpression(
          final List<LogProcessorExpression> expressions) throws LPRestletException {
        if (expressions == null || expressions.isEmpty()) {
          return Collections.emptyList();
        }
   
        final Integer currentTenantId = Utils.getCurrentTenantId(getRequest());
        return customAttributesManager.addLogProcessorExpression(currentTenantId, expressions);
      }

it calls following method

List<LogProcessorExpression> addLogProcessorExpression(final Integer currentTenantId,
                                                         final List<LogProcessorExpression> expressions)
      throws LPRestletException {
    final Map<String, LogProcessorExpression> cache = getCacheByCustomAttributeName(expressions);
    try {
      final List<Customattributesmetadata> cams =
          getCustomAttributesMetaDataForTenant(currentTenantId);

      for (final Customattributesmetadata metadata : cams) {
        if (cache.containsKey(metadata.getAttributecolumnname())) {
         
          metadata.setLogprocessorexpression(
              cache.get(metadata.getAttributecolumnname()).toString());
        }
        metadata.save();
      }
    } catch (final TorqueException e) {
      final String error = "Failed to update LogExpression custom attributes";
      LOGGER.error(error, e);
      throw new LPRestletException(error, e);
    }
    return expressions;
  }

which calls to other methods in chain. what I realized when accessing this endpoint as  

     curl -H "Authorization:Basic Y3VyYasqrwqrjQGdtYWlsLmNvbTp0YXAzYWg=" -H"Content-Type:application/json" -v http://172.10.501.540:8080/api/rest/msp/attributes -d '[{"source": "ad", "attributePrefix": "ad_", "attributeName": "department"}]'  

That it returns

    {"code":500,"message":"The server encountered an unexpected condition which prevented it from fulfilling the request"}

When I looked at the logs, I see lines as  

            at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
            at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
            at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.shn.api.dto.LogProcessorExpression
            at com.shn.api.restlet.logprocessor.CustomAttributesManager.getCacheByCustomAttributeName(CustomAttributesManager.java:55)
            at com.shn.api.restlet.logprocessor.CustomAttributesManager.addLogProcessorExpression(CustomAttributesManager.java:24)
            at com.shn.api.restlet.logprocessor.CustomAttributeMetadataRestlet.addLogProcessorExpression(CustomAttributeMetadataRestlet.java:44)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:606)
            at org.restlet.resource.ServerResource.doHandle(ServerResource.java:521)
            ... 67 more

**Question**  
- Why is it not casting them to `List<LogProcessorExpression>`?  
- What do I need to do to fix it?