-
Notifications
You must be signed in to change notification settings - Fork 343
feat(java): implement FinalFieldReplaceResolveSerializer for final fields with writeReplace/readResolve methods #2917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
3bf0bf1
42bf59c
6a897ca
4205700
db65e9d
eb12a80
98ea4f4
ab83703
55ebf06
0645ed9
9bc39d2
81cfb74
8c7127a
cf8b80d
446cc65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.fory.serializer; | ||
|
|
||
| import org.apache.fory.Fory; | ||
| import org.apache.fory.memory.MemoryBuffer; | ||
|
|
||
| /** | ||
| * Serializer for class which 1) has jdk `writeReplace`/`readResolve` method defined, 2) is a final | ||
| * field of a class. //TODO do we ned to write the flag REPLACED_NEW_TYPE/REPLACED_SAME_TYPE even | ||
|
||
| * for the final field? | ||
| */ | ||
| @SuppressWarnings({"unchecked", "rawtypes"}) | ||
| public class FinalFieldReplaceResolveSerializer extends ReplaceResolveSerializer { | ||
|
|
||
| public FinalFieldReplaceResolveSerializer(Fory fory, Class type) { | ||
| super(fory, type, true); | ||
|
||
| } | ||
|
|
||
| @Override | ||
| protected void writeObject( | ||
| MemoryBuffer buffer, Object value, MethodInfoCache jdkMethodInfoCache) { | ||
| jdkMethodInfoCache.objectSerializer.write(buffer, value); | ||
| } | ||
|
|
||
| @Override | ||
| protected Object readObject(MemoryBuffer buffer) { | ||
| MethodInfoCache jdkMethodInfoCache = getMethodInfoCache(type); | ||
| Object o = jdkMethodInfoCache.objectSerializer.read(buffer); | ||
| ReplaceResolveInfo replaceResolveInfo = jdkMethodInfoCache.info; | ||
| if (replaceResolveInfo.readResolveMethod == null) { | ||
| return o; | ||
| } | ||
| return replaceResolveInfo.readResolve(o); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.