title: failed to lazily initialize a collection, could not initialize proxy For converting JSON to Entity
body: <p>I have a java project which works with hibernate and spring framework . I should convert my entity to json and save the entity to DataBase, after that read json and convert it to my entity. Also my main entity has some entities which are loaded lazily.I used below code to convert my entity to json which worked that I used link below.</p>
  
  <p><a href="https://stackoverflow.com/questions/21708339/">Avoid Jackson serialization on non fetched lazy objects</a></p>
  
  <pre><code>            String arg = "";
              ObjectMapper mapper = new ObjectMapper();
              Hibernate4Module module = new Hibernate4Module();
              mapper.registerModule(module);
              mapper.enableDefaultTyping();
  
              try {
                  arg = mapper.writeValueAsString(arguments);
              } catch (IOException e) {
                  logger.error("Uncaught exception in thread: " + ExceptionUtils.getStringFromExceptionStackTrace(e));
              }
  </code></pre>
  
  <p>but, reading from json to Entity doesn't work probably.</p>
  
  <pre><code>            ObjectMapper mapper = new ObjectMapper();
              Hibernate4Module module = new Hibernate4Module();
              mapper.registerModule(module);
              module.disable(Hibernate4Module.Feature.FORCE_LAZY_LOADING);
              module.enable(Hibernate4Module.Feature.SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS);
              mapper.enableDefaultTyping();
              return mapper.readValue(jsonObject,Object[].class);
  </code></pre>
  
  <p>I got below exception:</p>
  
  <blockquote>
    <p>com.fasterxml.jackson.databind.JsonMappingException: failed to lazily
    initialize a collection, could not initialize proxy - no Session
    (through reference chain:
    Object[][0]->com.rayan.banking.privatebanking.model.entity.Contract["financialAgreementList"]->java.util.ArrayList[0]->com.rayan.banking.privatebanking.model.entity.FinancialAgreement["financialAgreementService"])
          at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:210)
          at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:177)
          at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.wrapAndThrow(BeanDeserializerBase.java:1474)
          at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:260)
          at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:125)
          at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:245)
          at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:217)
          at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:25)
          at com.fasterxml.jackson.databind.jsontype.impl.AsArrayTypeDeserializer._deserialize(AsArrayTypeDeserializer.java:110)
          at com.fasterxml.jackson.databind.jsontype.impl.AsArrayTypeDeserializer.deserializeTypedFromArray(AsArrayTypeDeserializer.java:50)
          at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserializeWithType(CollectionDeserializer.java:278)
          at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:518)
          at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:95)
          at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:258)
          at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:125)
          at com.fasterxml.jackson.databind.jsontype.impl.AsArrayTypeDeserializer._deserialize(AsArrayTypeDeserializer.java:110)
          at com.fasterxml.jackson.databind.jsontype.impl.AsArrayTypeDeserializer.deserializeTypedFromAny(AsArrayTypeDeserializer.java:68)
          at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserializeWithType(UntypedObjectDeserializer.java:550)
          at com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:158)
          at com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:17)
          at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3736)
          at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2726)</p>
  </blockquote>