| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  | package json_util | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"errors" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type RawMessage []byte | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-13 09:59:10 +00:00
										 |  |  | // MarshalJSON: Customize json.RawMessage default behavior
 | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  | func (m RawMessage) MarshalJSON() ([]byte, error) { | 
					
						
							|  |  |  | 	if len(m) == 0 { | 
					
						
							|  |  |  | 		return []byte("null"), nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return m, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-13 09:59:10 +00:00
										 |  |  | // UnmarshalJSON: sets *m to a copy of data.
 | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  | func (m *RawMessage) UnmarshalJSON(data []byte) error { | 
					
						
							|  |  |  | 	if m == nil { | 
					
						
							|  |  |  | 		return errors.New("json.RawMessage: UnmarshalJSON on nil pointer") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	*m = append((*m)[0:0], data...) | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } |