Skip to content

Commit

Permalink
Merge pull request #201 from mohrezaei/utf8
Browse files Browse the repository at this point in the history
17.1.1: Fix json deserialized without relationships.
  • Loading branch information
mohrezaei authored Sep 1, 2019
2 parents 8ba45b3 + a53a438 commit 0e466e7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Change Log
## 17.1.2 - 2019-09-01
### Bug Fixes:
- Fix json deserialization without relationships

## 17.1.0 - 2019-07-16
### Enhancements:
- Add support for test file charset
Expand Down
2 changes: 1 addition & 1 deletion build/reladomo-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
under the License.
-->
<project name="mithra-config" default="determine-jdk">
<property name="reladomo.version" value="17.1.0"/>
<property name="reladomo.version" value="17.1.1"/>
<property name="snapshot" value=""/>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.gs.fw.finder.Navigation;
import com.gs.reladomo.metadata.ReladomoClassMetaData;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.impl.factory.Maps;
import org.eclipse.collections.impl.list.mutable.FastList;
import org.eclipse.collections.impl.map.mutable.UnifiedMap;
import org.eclipse.collections.impl.set.mutable.UnifiedSet;
Expand All @@ -82,6 +83,7 @@
*/
public class ReladomoDeserializer<T extends MithraObject>
{
private static final Map<String, Object> EMPTY_MAP = Maps.fixedSize.of();
protected static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
private static final Object[] NULL_ARGS = (Object[]) null;
private static final Object[] SINGLE_NULL = new Object[1];
Expand Down Expand Up @@ -546,7 +548,7 @@ protected void wireRelationshipsForList(DeserializationClassMetaData metaData, L
wireRelationshipsForInMemory(metaData, partialDeserialized);
break;
case ReladomoSerializationContext.DETACHED_STATE:
if (partialDeserialized.partialRelationships != null)
if (partialDeserialized.partialRelationships != EMPTY_MAP)
{
detached.add(partialDeserialized);
}
Expand Down Expand Up @@ -1081,13 +1083,13 @@ protected static class PartialDeserialized
protected Timestamp processingDate;
protected BitSet populatedAttributes;
protected int state;
protected Map<String, Object> partialRelationships; //Object is either PartialDeserialized or List<PartialDeserialized>
protected Map<String, Object> partialRelationships = EMPTY_MAP; //Object is either PartialDeserialized or List<PartialDeserialized>
protected byte deserializedState;
protected MithraObject deserialized; // constructed at the end of the stream

protected void storeRelated(RelatedFinder relatedFinder, Object related)
{
if (this.partialRelationships == null)
if (this.partialRelationships == EMPTY_MAP)
{
this.partialRelationships = UnifiedMap.newMap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.gs.fw.common.mithra.test.domain.BitemporalOrder;
import com.gs.fw.common.mithra.test.domain.BitemporalOrderFinder;
import com.gs.fw.common.mithra.test.domain.Order;
import com.gs.fw.common.mithra.test.domain.OrderFinder;
import com.gs.fw.common.mithra.test.MithraTestAbstract;
import com.gs.fw.common.mithra.test.domain.*;
import com.gs.fw.common.mithra.test.util.serializer.TestBitemporalRoundTripStringBased;
import com.gs.fw.common.mithra.test.util.serializer.TestRoundTripStringBased;
import com.gs.fw.common.mithra.util.serializer.SerializationConfig;
import com.gs.fw.common.mithra.util.serializer.Serialized;
import org.junit.Assert;
import org.junit.Test;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;

public class ExampleJacksonReladomoBitemporalSerializerTest extends TestBitemporalRoundTripStringBased
{
@Override
Expand Down Expand Up @@ -92,4 +95,31 @@ public void testOrderWithRemovedItem() throws Exception
assertEquals(0, order.getItems().size());
}

@Test
public void testInMemoryNoRelationships() throws Exception
{
String serialized = "{\n" +
" \"_rdoClassName\" : \"com.gs.fw.common.mithra.test.domain.BitemporalOrderItem\",\n" +
// " \"_rdoState\" : 20,\n" +
" \"id\" : 70459,\n" +
" \"orderId\" : 1,\n" +
" \"productId\" : 1,\n" +
" \"quantity\" : 20.0,\n" +
" \"originalPrice\" : 10.5,\n" +
" \"discountPrice\" : 10.5,\n" +
" \"state\" : \"In-Progress\",\n" +
" \"businessDate\" : 1567363437186\n" +
"}\n";
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JacksonReladomoModule());
mapper.enable(SerializationFeature.INDENT_OUTPUT);
JavaType customClassCollection = mapper.getTypeFactory().constructCollectionLikeType(Serialized.class, BitemporalOrderItem.class);

Serialized<BitemporalOrderItem> back = mapper.readValue(serialized, customClassCollection);
BitemporalOrderItem wrapped = back.getWrapped();
Assert.assertEquals(70459, wrapped.getId());
Assert.assertEquals("In-Progress", wrapped.getState());
Assert.assertEquals(BitemporalOrderItemFinder.processingDate().getInfinityDate(), wrapped.getProcessingDate());
}

}

0 comments on commit 0e466e7

Please sign in to comment.