Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2013 SAP AG Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 package com.sap.core.odata.core.ep.consumer;
 
 import java.util.Map;
 

Author(s):
SAP AG
 
 public class JsonEntityConsumer {

  
Default used charset for writer and response content header
 
   private static final String DEFAULT_CHARSET = "UTF-8";
 
   public ODataEntry readEntry(final EdmEntitySet entitySetfinal InputStream contentfinal EntityProviderReadProperties propertiesthrows EntityProviderException {
     JsonReader reader = null;
     EntityProviderException cachedException = null;
 
     try {
       EntityInfoAggregator eia = EntityInfoAggregator.create(entitySet);
       reader = createJsonReader(content);
 
       JsonEntryConsumer jec = new JsonEntryConsumer(readereiaproperties);
       ODataEntry result = jec.readSingleEntry();
       return result;
     } catch (UnsupportedEncodingException e) {
       cachedException = new EntityProviderException(.e);
       throw cachedException;
     } finally {// NOPMD (suppress DoNotThrowExceptionInFinally)
       if (reader != null) {
         try {
           reader.close();
         } catch (IOException e) {
           if (cachedException != null) {
             throw cachedException;
           } else {
             throw new EntityProviderException(.e);
           }
         }
       }
     }
   }
 
   public ODataFeed readFeed(final EdmEntitySet entitySetfinal InputStream contentfinal EntityProviderReadProperties readPropertiesthrows EntityProviderException {
     JsonReader reader = null;
     EntityProviderException cachedException = null;
 
     try {
       EntityInfoAggregator eia = EntityInfoAggregator.create(entitySet);
       reader = createJsonReader(content);
 
       JsonFeedConsumer jfc = new JsonFeedConsumer(readereiareadProperties);
       ODataFeed result = jfc.readFeedStandalone();
 
       return result;
     } catch (UnsupportedEncodingException e) {
       cachedException = new EntityProviderException(.e);
       throw cachedException;
     } finally {// NOPMD (suppress DoNotThrowExceptionInFinally)
       if (reader != null) {
         try {
           reader.close();
         } catch (IOException e) {
           if (cachedException != null) {
             throw cachedException;
           } else {
             throw new EntityProviderException(.e);
           }
         }
       }
     }
   }
 
  public Map<StringObjectreadProperty(final EdmProperty propertyfinal InputStream contentfinal EntityProviderReadProperties readPropertiesthrows EntityProviderException {
    JsonReader reader = null;
    EntityProviderException cachedException = null;
    try {
      reader = createJsonReader(content);
      return new JsonPropertyConsumer().readPropertyStandalone(readerpropertyreadProperties);
    } catch (final UnsupportedEncodingException e) {
      cachedException = new EntityProviderException(.e);
      throw cachedException;
    } finally {// NOPMD (suppress DoNotThrowExceptionInFinally)
      if (reader != null) {
        try {
          reader.close();
        } catch (final IOException e) {
          if (cachedException != null) {
            throw cachedException;
          } else {
            throw new EntityProviderException(.e);
          }
        }
      }
    }
  }
    if (content == null) {
          .addContent("Got not supported NULL object as content to de-serialize."));
    }
    if (content instanceof InputStream) {
      return new JsonReader(new InputStreamReader((InputStreamcontent));
    }
        .addContent("Found not supported content of class '" + content.getClass() + "' to de-serialize."));
  }
New to GrepCode? Check out our FAQ X