Search in sources :

Example 1 with JSONParserTemplateFactory

use of org.whole.lang.json.util.JSONParserTemplateFactory in project whole by wholeplatform.

the class JSONLDPersistenceKit method doReadModel.

protected IEntity doReadModel(IPersistenceProvider pp) throws Exception {
    JsonFactory factory = new JsonFactory();
    JsonParser parser = factory.createParser(pp.getInputStream());
    parser.disable(Feature.AUTO_CLOSE_SOURCE);
    try {
        return new JSONLDEntityDecoder().clone(new JSONParserTemplateFactory(parser).create());
    } finally {
        parser.close();
    }
}
Also used : JSONLDEntityDecoder(org.whole.lang.json.util.JSONLDEntityDecoder) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JSONParserTemplateFactory(org.whole.lang.json.util.JSONParserTemplateFactory) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 2 with JSONParserTemplateFactory

use of org.whole.lang.json.util.JSONParserTemplateFactory in project whole by wholeplatform.

the class JSONSourcePersistenceKit method doReadModel.

protected IEntity doReadModel(IPersistenceProvider pp) throws Exception {
    JsonFactory factory = new JsonFactory();
    // factory.enable(JsonParser.Feature.ALLOW_COMMENTS);
    JsonParser parser = factory.createParser(pp.getInputStream());
    parser.disable(Feature.AUTO_CLOSE_SOURCE);
    try {
        return new JSONParserTemplateFactory(parser).create();
    } finally {
        parser.close();
    }
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) JSONParserTemplateFactory(org.whole.lang.json.util.JSONParserTemplateFactory) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 3 with JSONParserTemplateFactory

use of org.whole.lang.json.util.JSONParserTemplateFactory in project whole by wholeplatform.

the class JSONPersistencesTest method testStreamAndBuildParserEquivalence.

@Test
public void testStreamAndBuildParserEquivalence() throws Exception {
    IEntity sampleModelByFactory = JSONSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getClass().getResourceAsStream("sample.json")));
    ModelBuilderOperation op = new ModelBuilderOperation();
    new JSONParserTemplateFactory(new JsonFactory().createParser(sampleString)).apply(op);
    IEntity sampleModelByBuilder = ReflectionFactory.makeRootEntity(op.wGetResult());
    assertTrue(Matcher.match(sampleModelByFactory, sampleModelByBuilder));
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IEntity(org.whole.lang.model.IEntity) JsonFactory(com.fasterxml.jackson.core.JsonFactory) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) JSONParserTemplateFactory(org.whole.lang.json.util.JSONParserTemplateFactory) Test(org.junit.Test)

Aggregations

JsonFactory (com.fasterxml.jackson.core.JsonFactory)3 JSONParserTemplateFactory (org.whole.lang.json.util.JSONParserTemplateFactory)3 JsonParser (com.fasterxml.jackson.core.JsonParser)2 Test (org.junit.Test)1 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)1 StreamPersistenceProvider (org.whole.lang.codebase.StreamPersistenceProvider)1 JSONLDEntityDecoder (org.whole.lang.json.util.JSONLDEntityDecoder)1 IEntity (org.whole.lang.model.IEntity)1