Skip to content

Commit

Permalink
[Hardening] JSON serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Nov 16, 2020
1 parent a0f15e5 commit b743893
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions mapstore2_adapter/api/serializers.py
Expand Up @@ -15,6 +15,8 @@
from .models import MapStoreResource

import re
import six
import json
import base64
import logging

Expand All @@ -29,10 +31,10 @@ def to_internal_value(self, data):
return data

def to_representation(self, value):
try:
return value.blob
except Exception:
return value
data = value.blob if value and hasattr(value, 'blob') else value
if isinstance(data, six.string_types):
return json.loads(data)
return data


class JSONArraySerializerField(serializers.Field):
Expand Down Expand Up @@ -69,12 +71,7 @@ def to_representation(self, value):
if value:
from geonode.maps.models import Map
from geonode.maps.api.serializers import MapLayerSerializer
# from geonode.layers.api.serializers import LayerSerializer
map = Map.objects.get(id=value)
# return [
# MapLayerSerializer(embed=True, many=True).to_representation(map.layers),
# LayerSerializer(embed=True, many=True).to_representation(map.local_layers)
# ]
return MapLayerSerializer(embed=True, many=True).to_representation(map.layers)


Expand Down

0 comments on commit b743893

Please sign in to comment.