package org.wisdom.content.bodyparsers;

import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Provides;
import org.wisdom.api.content.BodyParser;
import org.wisdom.api.http.Context;
import org.wisdom.api.http.MimeTypes;
import org.wisdom.content.json.Json;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

@Component
@Provides
@Instantiate
public class BodyParserJson implements BodyParser {

    private final Logger logger = LoggerFactory.getLogger(BodyParserJson.class);

    public <T> T invoke(Context context, Class<T> classOfT) {
        T t = null;
        try {
            t = Json.mapper().readValue(context.getReader(), classOfT);
        } catch (IOException e) {
            logger.error("Error parsing incoming Json", e);
        }

        return t;
    }

    @Override
    public <T> T invoke(byte[] bytes, Class<T> classOfT) {
        T t = null;
        try {
            t = Json.mapper().readValue(bytes, classOfT);
        } catch (IOException e) {
            logger.error("Error parsing incoming Json", e);
        }

        return t;
    }

    public String getContentType() {
        return MimeTypes.JSON;
    }

}

@@ -190,24 +190,81 @@
 s.Provides;%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import org.w
@@ -289,24 +289,24 @@
 BodyParser;%0A
-
 import org.w
@@ -407,65 +407,8 @@
 son;
-%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aim
@@ -691,32 +691,187 @@
 ;%0A        try %7B%0A
+            final String content = context.body();%0A            if (content == null  %7C%7C content.length() == 0) %7B%0A                return null;%0A            %7D%0A
             t = 
@@ -903,22 +903,10 @@
 onte
-xt.getReader()
+nt
 , cl

Check for null and empty body before trying to map a json string to an object.