1
1
package org .pytorch .serve .http .messages ;
2
2
3
+ import com .google .gson .JsonObject ;
3
4
import java .nio .charset .Charset ;
4
5
import java .util .ArrayList ;
5
6
import java .util .Date ;
6
7
import java .util .List ;
8
+ import org .pytorch .serve .util .JsonUtils ;
9
+ import org .slf4j .Logger ;
10
+ import org .slf4j .LoggerFactory ;
7
11
8
12
public class DescribeModelResponse {
13
+ private static final Logger logger = LoggerFactory .getLogger (DescribeModelResponse .class );
9
14
10
15
private String modelName ;
11
16
private String modelVersion ;
@@ -22,7 +27,7 @@ public class DescribeModelResponse {
22
27
private List <Worker > workers ;
23
28
private Metrics metrics ;
24
29
private JobQueueStatus jobQueueStatus ;
25
- private String customizedMetadata ;
30
+ private JsonObject customizedMetadata ;
26
31
27
32
public DescribeModelResponse () {
28
33
workers = new ArrayList <>();
@@ -160,10 +165,16 @@ public void setJobQueueStatus(JobQueueStatus jobQueueStatus) {
160
165
}
161
166
162
167
public void setCustomizedMetadata (byte [] customizedMetadata ) {
163
- this .customizedMetadata = new String (customizedMetadata , Charset .forName ("UTF-8" ));
168
+ String stringMetadata = new String (customizedMetadata , Charset .forName ("UTF-8" ));
169
+ try {
170
+ this .customizedMetadata = JsonUtils .GSON .fromJson (stringMetadata , JsonObject .class );
171
+ } catch (com .google .gson .JsonSyntaxException ex ) {
172
+ logger .warn ("Customized metadata should be a dictionary." );
173
+ this .customizedMetadata = new JsonObject ();
174
+ }
164
175
}
165
176
166
- public String getCustomizedMetadata () {
177
+ public JsonObject getCustomizedMetadata () {
167
178
return customizedMetadata ;
168
179
}
169
180
0 commit comments