Subclasses should override this method for JSON encoding.
960311
def to_json(self, value):
        """"""
        if not self.is_valid(value):
            raise ex.SerializeException('Invalid value: {}'.format(value))
        return value
568688
private void overrideUseMavenPatterns(T overrider, Class overriderClass) {
        if (useMavenPatternsOverrideList.contains(overriderClass.getSimpleName())) {
            try {
                Field useMavenPatternsField = overriderClass.getDeclaredField("useMavenPatterns");
                useMavenPatternsField.setAccessible(true);
                Object useMavenPatterns = useMavenPatternsField.get(overrider);

                if (useMavenPatterns == null) {
                    Field notM2CompatibleField = overriderClass.getDeclaredField("notM2Compatible");
                    notM2CompatibleField.setAccessible(true);
                    Object notM2Compatible = notM2CompatibleField.get(overrider);
                    if (notM2Compatible instanceof Boolean && notM2Compatible != null) {
                        useMavenPatternsField.set(overrider, !(Boolean)notM2Compatible);
                    }
                }
            } catch (NoSuchFieldException | IllegalAccessException e) {
                converterErrors.add(getConversionErrorMessage(overrider, e));
            }
        }
    }
813738
function mergeJson(original, override) {
            return _.merge(original, override, function (a, b, key, aParent, bParent) {
                if (_.isUndefined(b)) {
                    aParent[key] = undefined;
                    return;
                }
            });
        }
675489
def get_json_encoders_for_type(self, type_to_encode: type) -> Optional[Iterable[JSONEncoder]]:
        
        if type_to_encode not in self._json_encoders:
            return None
        return self._json_encoders[type_to_encode]
520355
private static void applyOverrides() {
        // Get the appropriate InputStream to read overrides from, if any.
        InputStream stream = getContentTypesPropertiesStream();
        if (stream == null) {
            return;
        }

        try {
            try {
                // Read the properties file...
                Properties overrides = new Properties();
                overrides.load(stream);
                // And translate its mapping to ours...
                for (Map.Entry<Object, Object> entry : overrides.entrySet()) {
                    String extension = (String) entry.getKey();
                    String mimeType = (String) entry.getValue();
                    add(mimeType, extension);
                }
            } finally {
                stream.close();
            }
        } catch (IOException ignored) {
        }
    }
386871
def override(self, obj):
        """"""
        for field in obj.__class__.export_fields:
            setattr(self, field, getattr(obj, field))
448505
def _dumps(obj, cls=pyjson.JSONEncoder):
    

    class WithBytes(cls):
        """
        JSON encoder that supports L{bytes}.
        """

        def default(self, o):
            if isinstance(o, bytes):
                warnings.warn(
                    "Eliot will soon stop supporting encoding bytes in JSON"
                    " on Python 3", DeprecationWarning
                )
                return o.decode("utf-8")
            return cls.default(self, o)

    return pyjson.dumps(obj, cls=WithBytes).encode("utf-8")
431923
def to_json(value, **kwargs):
        """"""
        if isinstance(value, HasProperties):
            return value.serialize(**kwargs)
        try:
            return json.loads(json.dumps(value))
        except TypeError:
            raise TypeError(
                "Cannot convert type {} to JSON without calling 'serialize' "
                "on an instance of Instance Property and registering a custom "
                "serializer".format(value.__class__.__name__)
            )
935
def json_encode_default(obj):
    '''
    
    '''
    if isinstance(obj, (datetime, date)):
        result = dt2ts(obj)
    else:
        result = json_encoder.default(obj)
    return to_encoding(result)
129759
public JsonPropertyCoder<T, P> fix() {
		JsonPropertyCoder<T, P> coder = null;
		try {
			coder = coderClass.newInstance();
		} catch (InstantiationException e) {
			throw new IllegalArgumentException(e);
		} catch (IllegalAccessException e) {
			throw new IllegalArgumentException(e);
		}
		coder.name = this.name;
		coder.coder = this.coder;
		coder.router = this.router;

		return coder;
	}
142988
public void setFromJSON(Context context, JSONObject properties) {
        String backgroundResStr = optString(properties, Properties.background);
        if (backgroundResStr != null && !backgroundResStr.isEmpty()) {
            final int backgroundResId = getId(context, backgroundResStr, "drawable");
            setBackGround(context.getResources().getDrawable(backgroundResId, null));
        }

        setBackgroundColor(getJSONColor(properties, Properties.background_color, getBackgroundColor()));
        setGravity(optInt(properties, TextContainer.Properties.gravity, getGravity()));
        setRefreshFrequency(optEnum(properties, Properties.refresh_freq, getRefreshFrequency()));
        setTextColor(getJSONColor(properties, Properties.text_color, getTextColor()));
        setText(optString(properties, Properties.text, (String) getText()));
        setTextSize(optFloat(properties, Properties.text_size, getTextSize()));

        final JSONObject typefaceJson = optJSONObject(properties, Properties.typeface);

        if (typefaceJson != null) {
            try {
                Typeface typeface = WidgetLib.getTypefaceManager().getTypeface(typefaceJson);
                setTypeface(typeface);
            } catch (Throwable e) {
                Log.e(TAG, e, "Couldn't set typeface from properties: %s", typefaceJson);
            }
        }
    }
837228
def set_json(self, value: object):
        '''
        
        '''
        self.set_content(modjson.dumps(value, cls=ExtendedJSONEncoder),
                         content_type='application/json')
373528
def json_serial(cls, obj):
        """"""

        if isinstance(obj, datetime):
            serial = obj.isoformat()

        elif issubclass(obj.__class__, enum.Enum):
            serial = obj.value

        elif isinstance(obj, timedelta):
            serial = str(obj)

        elif isinstance(obj, set):
            serial = list(x for x in obj)

        elif isinstance(obj, uuid.UUID):
            serial = str(obj)

        # FIXME: if you want to add one more custom serializer, think twice about `singledispatch`

        else:
            raise TypeError("Type not serializable %s in %s" % (type(obj), obj))

        return serial
307561
private JsonEncoding getJsonEncoding(MediaType contentType) {
		if (contentType != null && contentType.getCharset() != null) {
			Charset charset = contentType.getCharset();
			for (JsonEncoding encoding : JsonEncoding.values()) {
				if (charset.name().equals(encoding.getJavaName())) {
					return encoding;
				}
			}
		}
		return JsonEncoding.UTF8;
	}
948137
public JsonModelCoder<T> fix() {
		Map<String, JsonPropertyCoder<T, ?>> properties =
				new LinkedHashMap<String, JsonPropertyCoder<T, ?>>();
		for (String key : map.keySet()) {
			JsonPropertyBuilder<T, ?> builder = map.get(key);
			JsonPropertyCoder<T, ?> fixed = builder.fix();
			properties.put(key, fixed);
		}

		JsonModelCoder<T> fixed =
				new JsonModelCoder<T>(baseClass, treatUnknownKeyAsError, properties);
		return fixed;
	}
893203
def to_json(self, value):
        
        if self._enable_enforce_type:
            value = self.enforce_type(value)
        return super(XMLString, self).to_json(value)
885891
def override_spec(cls, **kwargs):
        """"""
        cls._default_spec.set(**kwargs)
        cls.spec.set(**kwargs)