Skip to content
Permalink
Browse files

Bug fixes for GWT jackson

  • Loading branch information...
richturner committed Aug 12, 2019
1 parent a6e48b1 commit 03fbde43080fe775b5b0f0320a0f2939c88aecad
@@ -0,0 +1,31 @@
/*
* Copyright 2016, OpenRemote Inc.
*
* See the CONTRIBUTORS.txt file in the distribution for a
* full listing of individual contributors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.openremote.app.client.assets.attributes;

import com.github.nmorel.gwtjackson.client.ObjectMapper;
import com.github.nmorel.gwtjackson.client.annotation.JsonMixIns;
import org.openremote.app.client.interop.jackson.DefaultJsonMixin;
import org.openremote.model.attribute.AttributeDescriptorImpl;
import org.openremote.model.attribute.AttributeValueDescriptorImpl;

@JsonMixIns({@JsonMixIns.JsonMixIn(target = AttributeDescriptorImpl.class, mixIn = DefaultJsonMixin.class)})
public interface AttributeDescriptorMapper
extends ObjectMapper<AttributeDescriptorImpl> {
}
@@ -0,0 +1,34 @@
/*
* Copyright 2016, OpenRemote Inc.
*
* See the CONTRIBUTORS.txt file in the distribution for a
* full listing of individual contributors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.openremote.app.client.assets.attributes;

import com.github.nmorel.gwtjackson.client.ObjectMapper;
import com.github.nmorel.gwtjackson.client.annotation.JsonMixIns;
import org.openremote.app.client.interop.jackson.DefaultJsonMixin;
import org.openremote.app.client.rest.EntityReader;
import org.openremote.app.client.rest.EntityWriter;
import org.openremote.model.attribute.AttributeLink;
import org.openremote.model.attribute.AttributeValueDescriptor;
import org.openremote.model.attribute.AttributeValueDescriptorImpl;

@JsonMixIns({@JsonMixIns.JsonMixIn(target = AttributeValueDescriptorImpl.class, mixIn = DefaultJsonMixin.class)})
public interface AttributeValueDescriptorMapper
extends ObjectMapper<AttributeValueDescriptorImpl> {
}
@@ -0,0 +1,46 @@
/*
* Copyright 2016, OpenRemote Inc.
*
* See the CONTRIBUTORS.txt file in the distribution for a
* full listing of individual contributors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.openremote.app.client.interop.jackson;

import com.github.nmorel.gwtjackson.client.JsonDeserializationContext;
import com.github.nmorel.gwtjackson.client.JsonDeserializer;
import com.github.nmorel.gwtjackson.client.JsonDeserializerParameters;
import com.github.nmorel.gwtjackson.client.stream.JsonReader;
import com.google.gwt.core.client.GWT;
import org.openremote.app.client.assets.attributes.AttributeDescriptorMapper;
import org.openremote.app.client.assets.attributes.AttributeValueDescriptorMapper;
import org.openremote.model.attribute.AttributeDescriptor;
import org.openremote.model.attribute.AttributeValueDescriptor;

public class AttributeDescriptorDeserializer extends JsonDeserializer<AttributeDescriptor> {

private static final AttributeDescriptorDeserializer INSTANCE = new AttributeDescriptorDeserializer();
private static final AttributeDescriptorMapper MAPPER = GWT.create(AttributeDescriptorMapper.class);

public static AttributeDescriptorDeserializer getInstance() {
return INSTANCE;
}

@Override
protected AttributeDescriptor doDeserialize(JsonReader reader, JsonDeserializationContext ctx, JsonDeserializerParameters params) {
// Read entire object in
return MAPPER.read(reader.nextValue());
}
}
@@ -0,0 +1,44 @@
/*
* Copyright 2016, OpenRemote Inc.
*
* See the CONTRIBUTORS.txt file in the distribution for a
* full listing of individual contributors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.openremote.app.client.interop.jackson;

import com.github.nmorel.gwtjackson.client.JsonDeserializationContext;
import com.github.nmorel.gwtjackson.client.JsonDeserializer;
import com.github.nmorel.gwtjackson.client.JsonDeserializerParameters;
import com.github.nmorel.gwtjackson.client.stream.JsonReader;
import com.google.gwt.core.client.GWT;
import org.openremote.app.client.assets.attributes.AttributeValueDescriptorMapper;
import org.openremote.model.attribute.AttributeValueDescriptor;

public class AttributeValueDescriptorDeserializer extends JsonDeserializer<AttributeValueDescriptor> {

private static final AttributeValueDescriptorDeserializer INSTANCE = new AttributeValueDescriptorDeserializer();
private static final AttributeValueDescriptorMapper MAPPER = GWT.create(AttributeValueDescriptorMapper.class);

public static AttributeValueDescriptorDeserializer getInstance() {
return INSTANCE;
}

@Override
protected AttributeValueDescriptor doDeserialize(JsonReader reader, JsonDeserializationContext ctx, JsonDeserializerParameters params) {
// Read entire object in
return MAPPER.read(reader.nextValue());
}
}
@@ -22,6 +22,8 @@
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.github.nmorel.gwtjackson.client.AbstractConfiguration;
import org.openremote.model.ValidationFailure;
import org.openremote.model.attribute.AttributeDescriptor;
import org.openremote.model.attribute.AttributeValueDescriptor;
import org.openremote.model.attribute.MetaItemDescriptor;
import org.openremote.model.geo.Position;
import org.openremote.model.value.*;
@@ -48,5 +50,7 @@ protected void configure() {
type(StringValue.class).serializer(ModelValueSerializer.class).deserializer(ModelValueDeserializer.class);
type(BooleanValue.class).serializer(ModelValueSerializer.class).deserializer(ModelValueDeserializer.class);
type(Position.class).serializer(PositionSerializer.class).deserializer(PositionDeserializer.class);
type(AttributeValueDescriptor.class).deserializer(AttributeValueDescriptorDeserializer.class);
type(AttributeDescriptor.class).deserializer(AttributeDescriptorDeserializer.class);
}
}
@@ -19,14 +19,10 @@
*/
package org.openremote.model.attribute;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.openremote.model.value.Value;

import java.util.Optional;

@JsonFormat(shape = JsonFormat.Shape.OBJECT)
@JsonDeserialize(as = AttributeDescriptorImpl.class)
public interface AttributeDescriptor {

@@ -19,11 +19,13 @@
*/
package org.openremote.model.attribute;

import com.fasterxml.jackson.annotation.JsonFormat;
import org.openremote.model.value.Value;
import org.openremote.model.value.Values;

import static org.openremote.model.attribute.MetaItemType.*;

@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum AttributeType implements AttributeDescriptor {

CONSOLE_NAME("consoleName", AttributeValueType.STRING),
@@ -19,7 +19,6 @@
*/
package org.openremote.model.attribute;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -30,7 +29,6 @@
import java.util.Optional;
import java.util.function.Function;

@JsonFormat(shape = JsonFormat.Shape.OBJECT)
@JsonDeserialize(as = AttributeValueDescriptorImpl.class)
public interface AttributeValueDescriptor {

@@ -19,6 +19,7 @@
*/
package org.openremote.model.attribute;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openremote.model.ValidationFailure;
import org.openremote.model.ValueHolder;
@@ -40,6 +41,7 @@
* Additional constraints and integrity rules upon attribute values can be declared by
* adding arbitrary {@link Meta} to an {@link Attribute}.
*/
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum AttributeValueType implements AttributeValueDescriptor {

STRING("edit", ValueType.STRING),
@@ -22,11 +22,13 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.openremote.model.ValidationFailure;
import org.openremote.model.ValueHolder;
import org.openremote.model.attribute.AttributeRef;
import org.openremote.model.attribute.AttributeValueType;
import org.openremote.model.attribute.AttributeValueDescriptor;
import org.openremote.model.attribute.AttributeValueDescriptorImpl;
import org.openremote.model.attribute.AttributeValueType;
import org.openremote.model.simulator.element.ColorSimulatorElement;
import org.openremote.model.simulator.element.NumberSimulatorElement;
import org.openremote.model.simulator.element.SwitchSimulatorElement;
@@ -47,7 +49,6 @@
})
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "elementType"
)
public abstract class SimulatorElement implements ValueHolder {

0 comments on commit 03fbde4

Please sign in to comment.
You can’t perform that action at this time.