Last change
on this file since 74 was 73, checked in by Bart Vastenhouw, 3 years ago |
Fix for IssueValue hashcode.
|
File size:
1.3 KB
|
Line | |
---|
1 | from typing import List
|
---|
2 |
|
---|
3 | from pyson.Deserializer import Deserializer
|
---|
4 | from pyson.ObjectMapper import ObjectMapper
|
---|
5 | from tudelft.utilities.immutablelist.Range import Range
|
---|
6 |
|
---|
7 | from geniusweb.issuevalue.DiscreteValue import DiscreteValue
|
---|
8 | from geniusweb.issuevalue.DiscreteValueSet import DiscreteValueSet
|
---|
9 | from geniusweb.issuevalue.NumberValueSet import NumberValueSet
|
---|
10 | from geniusweb.issuevalue.ValueSet import ValueSet
|
---|
11 |
|
---|
12 |
|
---|
13 | class 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.