
org.emfjson.jackson.databind.deser.ResourceDeserializer Maven / Gradle / Ivy
/*
* Copyright (c) 2015 Guillaume Hillairet.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Guillaume Hillairet - initial API and implementation
*
*/
package org.emfjson.jackson.databind.deser;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.emfjson.jackson.databind.EMFContext;
import org.emfjson.jackson.handlers.URIHandler;
import java.io.IOException;
import static org.emfjson.jackson.databind.EMFContext.Attributes.RESOURCE_SET;
public class ResourceDeserializer extends JsonDeserializer {
private final URIHandler uriHandler;
public ResourceDeserializer(URIHandler uriHandler) {
this.uriHandler = uriHandler;
}
@Override
public boolean isCachable() {
return true;
}
@Override
public Resource deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return deserialize(jp, ctxt, null);
}
@Override
public Resource deserialize(JsonParser jp, DeserializationContext ctxt, Resource intoValue) throws IOException {
final Resource resource = getResource(ctxt, intoValue);
if (resource == null) {
throw new IllegalArgumentException("Invalid resource");
}
EMFContext.init(resource, ctxt);
if (!jp.hasCurrentToken()) {
jp.nextToken();
}
JsonDeserializer
© 2015 - 2025 Weber Informatics LLC | Privacy Policy