source: geniuswebcore/geniusweb/issuevalue/ValueSetDeserializer.py@ 62

Last change on this file since 62 was 59, checked in by Wouter Pasman, 3 years ago

#44 manual commit of first public release, because this will cause the dist directory to move

File size: 1.3 KB
Line 
1from typing import List
2
3from pyson.Deserializer import Deserializer
4from pyson.ObjectMapper import ObjectMapper
5from tudelft.utilities.immutablelist.Range import Range
6
7from geniusweb.issuevalue.DiscreteValue import DiscreteValue
8from geniusweb.issuevalue.DiscreteValueSet import DiscreteValueSet
9from geniusweb.issuevalue.NumberValueSet import NumberValueSet
10from geniusweb.issuevalue.ValueSet import ValueSet
11
12
13class ValueSetDeserializer (Deserializer):
14
15 pyson= ObjectMapper()
16 '''
17 Deserializes a ValueSet by checking the name of the (one and only) property
18 in there.}. This property is coming from the concrete implementations that we
19 have: {@link NumberValueSet} and {@link DiscreteValueSet}. This way we can
20 avoid putting (redundant) type info in each and every valueset.
21
22 '''
23 def deserialize(self, data:object, clas: object) -> ValueSet:
24 if not isinstance(data, dict):
25 raise ValueError("Expected dict containing ValueSet but found "+str(data))
26 if "range" in data:
27 rangev:Range=self.pyson.parse(data['range'], Range)
28 return NumberValueSet(rangev)
29 if "values" in data:
30 values = self.pyson.parse(data['values'], List[DiscreteValue])
31 return DiscreteValueSet(values)
32 raise ValueError("Expected 'range' or 'values' property for ValueSet contents")
Note: See TracBrowser for help on using the repository browser.